Reputation: 111
I tried to get the text from a random youtube video just to try out the API but it does not return anything. It does workwhen using the sample file 'audio.raw' from this repository. https://github.com/GoogleCloudPlatform/golang-samples/tree/master/speech/testdata
The youtube video i'm using : https://www.youtube.com/watch?v=liAsT4DqalQ The english is pretty clear and the audio version i have locally is clear. The file is of type webm maybe this is the problem, i tried with a m4a file but no luck :x
My code is just like the one from the async simple, the really weird part is that i do not get any error...
package main
import (
"context"
"fmt"
"log"
speech "cloud.google.com/go/speech/apiv1"
speechpb "google.golang.org/genproto/googleapis/cloud/speech/v1"
)
func main() {
ctx := context.Background()
client, err := speech.NewClient(ctx)
if err != nil {
log.Fatal(err)
}
req := &speechpb.LongRunningRecognizeRequest{
Config: &speechpb.RecognitionConfig{
Encoding: speechpb.RecognitionConfig_LINEAR16,
SampleRateHertz: 16000,
LanguageCode: "en-US",
},
Audio: &speechpb.RecognitionAudio{
AudioSource: &speechpb.RecognitionAudio_Uri{Uri: "gs://BUCKET_NAME/eng.webm"},
},
}
op, err := client.LongRunningRecognize(ctx, req)
if err != nil {
panic(err)
}
resp, err := op.Wait(ctx)
if err != nil {
panic(err)
}
// Print the results.
for _, result := range resp.Results {
for _, alt := range result.Alternatives {
fmt.Printf("\"%v\" (confidence=%3f)\n", alt.Transcript, alt.Confidence)
}
}
}
Upvotes: 1
Views: 332