Enha: google-tts replay speed
This commit is contained in:
@@ -27,6 +27,7 @@ type GoogleTranslateOrator struct {
|
|||||||
// text buffer and interrupt flag
|
// text buffer and interrupt flag
|
||||||
textBuffer strings.Builder
|
textBuffer strings.Builder
|
||||||
interrupt bool
|
interrupt bool
|
||||||
|
Speed float32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *GoogleTranslateOrator) stoproutine() {
|
func (o *GoogleTranslateOrator) stoproutine() {
|
||||||
@@ -141,8 +142,14 @@ func (o *GoogleTranslateOrator) Speak(text string) error {
|
|||||||
// Wrap in io.NopCloser since GenerateSpeech returns io.Reader (no close needed)
|
// Wrap in io.NopCloser since GenerateSpeech returns io.Reader (no close needed)
|
||||||
body := io.NopCloser(reader)
|
body := io.NopCloser(reader)
|
||||||
defer body.Close()
|
defer body.Close()
|
||||||
// Exactly the same ffplay piping as KokoroOrator
|
// Build ffplay command with optional speed filter
|
||||||
cmd := exec.Command("ffplay", "-nodisp", "-autoexit", "-i", "pipe:0")
|
args := []string{"-nodisp", "-autoexit"}
|
||||||
|
if o.Speed > 0.1 && o.Speed != 1.0 {
|
||||||
|
// atempo range is 0.5 to 2.0; you might clamp it here
|
||||||
|
args = append(args, "-af", fmt.Sprintf("atempo=%.2f", o.Speed))
|
||||||
|
}
|
||||||
|
args = append(args, "-i", "pipe:0")
|
||||||
|
cmd := exec.Command("ffplay", args...)
|
||||||
stdin, err := cmd.StdinPipe()
|
stdin, err := cmd.StdinPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get stdin pipe: %w", err)
|
return fmt.Errorf("failed to get stdin pipe: %w", err)
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ func NewOrator(log *slog.Logger, cfg *config.Config) Orator {
|
|||||||
orator := &GoogleTranslateOrator{
|
orator := &GoogleTranslateOrator{
|
||||||
logger: log,
|
logger: log,
|
||||||
speech: speech,
|
speech: speech,
|
||||||
|
Speed: cfg.TTS_SPEED,
|
||||||
}
|
}
|
||||||
go orator.readroutine()
|
go orator.readroutine()
|
||||||
go orator.stoproutine()
|
go orator.stoproutine()
|
||||||
|
|||||||
Reference in New Issue
Block a user