I'm trying out the speech-to-text apiv2 in go and I am getting this error:
Failed to recognize: rpc error: code = InvalidArgument desc = Invalid `language_codes`: field must be non-empty.
From what I understand, this field is optional:
Regardless, there is no LanguageCodes
field in the RecognitionConfig
struct.
package main
import (
speech "cloud.google.com/go/speech/apiv2"
speechpb "cloud.google.com/go/speech/apiv2/speechpb"
"context"
"fmt"
"log"
)
func main() {
ctx := context.Background()
client, err := speech.NewClient(ctx)
gcsURI := fmt.Sprintf("gs://%s/%s", "my-bucket", "myfile.mp3")
config := &speechpb.RecognitionConfig{
DecodingConfig: &speechpb.RecognitionConfig_AutoDecodingConfig{},
}
audioSource := &speechpb.RecognizeRequest_Uri{
Uri: gcsURI
}
req := &speechpb.RecognizeRequest{
Config: config,
Recognizer: "projects/my-project/locations/global/recognizers/_",
AudioSource: audioSource,
}
resp, err := client.Recognize(ctx, req)
if err != nil {
// TODO: Handle error.
log.Fatalf("Failed to recognize: %v", err)
}
for _, result := range resp.Results {
for _, alt := range result.Alternatives {
fmt.Printf("\"%v\" (confidence=%3f)\n", alt.Transcript, alt.Confidence)
}
}