Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
texttospeech
✓ cloud.google.com/go/texttospeech
Synthesizes speech from text using Google Cloud Text-to-Speech.
package main
import (
"context"
"fmt"
texttospeech "cloud.google.com/go/texttospeech/apiv1"
"cloud.google.com/go/texttospeech/apiv1/texttospeechpb"
)
func main() {
ctx := context.Background()
client, err := texttospeech.NewClient(ctx)
if err != nil {
panic(err)
}
defer client.Close()
req := &texttospeechpb.SynthesizeSpeechRequest{
Input: &texttospeechpb.SynthesisInput{InputSource: &texttospeechpb.SynthesisInput_Text{Text: "Hello"}},
Voice: &texttospeechpb.VoiceSelectionParams{LanguageCode: "en-US"},
AudioConfig: &texttospeechpb.AudioConfig{AudioEncoding: texttospeechpb.AudioEncoding_MP3},
}
resp, err := client.SynthesizeSpeech(ctx, req)
if err != nil {
panic(err)
}
fmt.Println("Audio content length:", len(resp.AudioContent))
}
Debug
Known issues
No known issues recorded.
Upgrade
Version history
1.21.0latest on pkg.go.dev
Audit
Dependencies
No dependency data recorded yet.