Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
ringsaturn committed Dec 4, 2023
1 parent 85aec29 commit 7f345b1
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions README.md
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>.

0 comments on commit 7f345b1

Please sign in to comment.