-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85aec29
commit 7f345b1
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,61 @@ | ||
# Azure TTS (Text to Speech) API wrapper for Go. | ||
|
||
## Quick Start | ||
|
||
```bash | ||
go get github.com/ringsaturn/azuretts | ||
``` | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/ringsaturn/azuretts" | ||
) | ||
|
||
func buildFileName(speak *azuretts.Speak) string { | ||
return fmt.Sprintf("%s_rate=%v_styledgree=%v.mp3", | ||
speak.Voice.Name, | ||
speak.Voice.ExpressAs.Prosody.Rate, | ||
speak.Voice.ExpressAs.Styledegree, | ||
) | ||
} | ||
|
||
func main() { | ||
c := azuretts.NewClient( | ||
os.Getenv("SPEECH_KEY"), | ||
azuretts.Region(os.Getenv("SPEECH_REGION")), | ||
) | ||
speak := azuretts.NewSpeak( | ||
azuretts.WithLanguage(azuretts.LanguageZhCN), | ||
azuretts.WithVoiceName(azuretts.VoiceNameZhCNYunxiNeural), | ||
azuretts.WithStyle(azuretts.StyleChat), | ||
azuretts.WithRate(1), | ||
azuretts.WithVoiceStyledegree(2), | ||
azuretts.WithSpeechText("你好,世界"), | ||
azuretts.WithVolume(100), | ||
) | ||
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(buildFileName(speak), b.Body, 0644) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
``` | ||
|
||
## Thanks | ||
|
||
I learned a lot from <https://github.com/jesseward/azuretexttospeech>. |