Skip to content

Commit

Permalink
Add cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ringsaturn committed Dec 5, 2023
1 parent 74a135e commit 72d9a6a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
tmp/
.env
*.mp3
cmd/azuretts/azuretts
52 changes: 52 additions & 0 deletions cmd/azuretts/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"context"
"flag"
"os"

"github.com/ringsaturn/azuretts"
)

var (
languageFlag = flag.String("language", "zh-CN", "Language Flags")
voiceFlag = flag.String("voice", azuretts.VoiceNameZhCNYunxiNeural.String(), "Voice Flags")
styleFlag = flag.String("style", azuretts.StyleChat.String(), "Style Flags")
rateFlag = flag.Int("rate", 1, "Rate")
styleDegreeFlag = flag.Int("styledegree", 2, "Style Degree")
volumeFlag = flag.Int("volume", 100, "Volume")
textFlag = flag.String("text", "你好,世界", "Text")
outputFileName = flag.String("output", "audio.mp3", "Output File Name")
)

func main() {
flag.Parse()

c := azuretts.NewClient(
os.Getenv("SPEECH_KEY"),
azuretts.Region(os.Getenv("SPEECH_REGION")),
)
speak := azuretts.NewSpeak(
azuretts.WithLanguage(azuretts.Language(*languageFlag)),
azuretts.WithVoiceName(azuretts.VoiceName(*voiceFlag)),
azuretts.WithStyle(azuretts.Style(*styleFlag)),
azuretts.WithRate(float64(*rateFlag)),
azuretts.WithVoiceStyledegree(float64(*styleDegreeFlag)),
azuretts.WithSpeechText(*textFlag),
azuretts.WithVolume(*volumeFlag),
)
b, err := c.GetSynthesize(context.Background(), &azuretts.SynthesisRequest{
Speak: speak,
Output: azuretts.AudioOutputFormat_Streaming_Audio16Khz32KbitrateMonoMp3,
})
if err != nil {
panic(err)
}
if err := b.Error(); err != nil {
panic(err)
}
err = os.WriteFile(*outputFileName, b.Body, 0644)
if err != nil {
panic(err)
}
}

0 comments on commit 72d9a6a

Please sign in to comment.