Skip to content

Instantly share code, notes, and snippets.

@dvonthenen
Created April 23, 2024 16:35
Show Gist options
  • Save dvonthenen/3feb4cfebe4f503f3fe8e949ea51f176 to your computer and use it in GitHub Desktop.
Save dvonthenen/3feb4cfebe4f503f3fe8e949ea51f176 to your computer and use it in GitHub Desktop.
[Go] Playground TTS
I dont know exactly how the mapping is done from the Checkboxes to the Options for the TTS,
but the Schema/Options class can be found here:
https://github.com/deepgram/deepgram-go-sdk/blob/main/pkg/client/interfaces/types-speak.go#L14
package main
import (
"context"
"encoding/json"
"fmt"
"os"
prettyjson "github.com/hokaccha/go-prettyjson"
speak "github.com/deepgram/deepgram-go-sdk/pkg/api/speak/v1"
interfaces "github.com/deepgram/deepgram-go-sdk/pkg/client/interfaces"
client "github.com/deepgram/deepgram-go-sdk/pkg/client/speak"
)
const (
textToSpeech string = "Hello, World!"
filePath string = "./test.mp3"
)
func main() {
// init library
client.InitWithDefault()
// Go context
ctx := context.Background()
// set the Transcription options
options := interfaces.SpeakOptions{
Model: "aura-asteria-en",
}
// create a Deepgram client
c := client.NewWithDefaults()
dg := speak.New(c)
// send/process file to Deepgram
res, err := dg.ToSave(ctx, filePath, textToSpeech, options)
if err != nil {
fmt.Printf("FromStream failed. Err: %v\n", err)
os.Exit(1)
}
data, err := json.Marshal(res)
if err != nil {
fmt.Printf("json.Marshal failed. Err: %v\n", err)
os.Exit(1)
}
// make the JSON pretty
prettyJson, err := prettyjson.Format(data)
if err != nil {
fmt.Printf("prettyjson.Marshal failed. Err: %v\n", err)
os.Exit(1)
}
fmt.Printf("\n\nResult:\n%s\n\n", prettyJson)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment