mirror of
https://github.com/taigrr/elevenlabs.git
synced 2026-04-02 03:08:57 -07:00
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:
@@ -69,7 +69,7 @@ func main() {
|
|||||||
text, _ := reader.ReadString('\n')
|
text, _ := reader.ReadString('\n')
|
||||||
go func() {
|
go func() {
|
||||||
// stream audio from elevenlabs using the first voice we found
|
// stream audio from elevenlabs using the first voice we found
|
||||||
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: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,11 +31,19 @@ func (so *SynthesisOptions) Clamp() {
|
|||||||
if so.SimilarityBoost > 1 || so.SimilarityBoost < 0 {
|
if so.SimilarityBoost > 1 || so.SimilarityBoost < 0 {
|
||||||
so.SimilarityBoost = 0.75
|
so.SimilarityBoost = 0.75
|
||||||
}
|
}
|
||||||
|
if so.Style > 1 || so.Style < 0 {
|
||||||
|
so.Style = 0.0
|
||||||
|
}
|
||||||
|
if so.UseSpeakerBoost != true && so.UseSpeakerBoost != false {
|
||||||
|
so.UseSpeakerBoost = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type SynthesisOptions struct {
|
type SynthesisOptions struct {
|
||||||
Stability float64 `json:"stability"`
|
Stability float64 `json:"stability"`
|
||||||
SimilarityBoost float64 `json:"similarity_boost"`
|
SimilarityBoost float64 `json:"similarity_boost"`
|
||||||
|
Style float64 `json:"style"`
|
||||||
|
UseSpeakerBoost bool `json:"use_speaker_boost"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SharingOptions struct {
|
type SharingOptions struct {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/faiface/beep"
|
"github.com/faiface/beep"
|
||||||
"github.com/faiface/beep/mp3"
|
"github.com/faiface/beep/mp3"
|
||||||
@@ -25,12 +26,23 @@ func main() {
|
|||||||
}
|
}
|
||||||
pipeReader, pipeWriter := io.Pipe()
|
pipeReader, pipeWriter := io.Pipe()
|
||||||
|
|
||||||
reader := bufio.NewReader(os.Stdin)
|
// record how long it takes to run and print out on exit
|
||||||
b, _ := io.ReadAll(reader)
|
start := time.Now()
|
||||||
text := string(b)
|
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() {
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user