Support command line text & new API attributes (#8)

* support `style` and `use_speaker_boost` API attrs

* support optional command line string as text

* print out time it took to run
This commit is contained in:
samy kamkar
2024-07-24 12:14:00 -07:00
committed by GitHub
parent 41f142ec2c
commit c585531fae
3 changed files with 25 additions and 5 deletions

View File

@@ -7,6 +7,7 @@ import (
"log"
"os"
"time"
"strings"
"github.com/faiface/beep"
"github.com/faiface/beep/mp3"
@@ -25,12 +26,23 @@ func main() {
}
pipeReader, pipeWriter := io.Pipe()
reader := bufio.NewReader(os.Stdin)
b, _ := io.ReadAll(reader)
text := string(b)
// record how long it takes to run and print out on exit
start := time.Now()
defer func() {
log.Println(time.Since(start))
}()
var text string
if len(os.Args) > 1 {
text = strings.Join(os.Args[1:], " ")
} else {
reader := bufio.NewReader(os.Stdin)
b, _ := io.ReadAll(reader)
text = string(b)
}
go func() {
err = client.TTSStream(ctx, pipeWriter, text, ids[0], types.SynthesisOptions{Stability: 0.75, SimilarityBoost: 0.75})
err = client.TTSStream(ctx, pipeWriter, text, ids[0], types.SynthesisOptions{Stability: 0.75, SimilarityBoost: 0.75, Style: 0.0, UseSpeakerBoost: false})
if err != nil {
panic(err)
}