func send(client *speech.Client, filename string) (string, error) { ctx := context.Background() data, err := ioutil.ReadFile(filename) if err != nil { return "", err } // Send the contents of the audio file with the encoding and // and sample rate information to be transcripted. req := &speechpb.AsyncRecognizeRequest{ Config: &speechpb.RecognitionConfig{ Encoding: speechpb.RecognitionConfig_LINEAR16, SampleRate: 16000, }, Audio: &speechpb.RecognitionAudio{ AudioSource: &speechpb.RecognitionAudio_Content{Content: data}, }, } op, err := client.AsyncRecognize(ctx, req) if err != nil { return "", err } return op.Name(), nil }