I am using Golang's SDK
this is my golang code
func (m *microsoft) Do(ctx context.Context, path string) (string, error) {
defer os.Remove(path)
accessKeyConfig := AccessKeyList[rand.Intn(len(AccessKeyList))]
subscription := accessKeyConfig.Key
region := accessKeyConfig.Region
file := path
audioConfig, err := audio.NewAudioConfigFromWavFileInput(file)
if err != nil {
fwlog.New(ctx).Info("", "audioConfigErr")
return "", err
}
defer audioConfig.Close()
config, err := speech.NewSpeechConfigFromSubscription(subscription, region)
if err != nil {
fwlog.New(ctx).Info("", "configErr")
return "", err
}
config.RequestWordLevelTimestamps()
defer config.Close()
speechRecognizer, err := speech.NewSpeechRecognizerFromConfig(config, audioConfig)
if err != nil {
fwlog.New(ctx).Info("", "speechRecognizerErr")
return "", err
}
defer speechRecognizer.Close()
speechRecognizer.SessionStarted(func(event speech.SessionEventArgs) {
defer event.Close()
fmt.Println("Session Started (ID=", event.SessionID, ")")
})
speechRecognizer.Recognizing(recognizingHandler)
speechRecognizer.Recognized(recognizedHandler)
//speechRecognizer.Recognizing(recognizedHandler)
speechRecognizer.SessionStopped(func(event speech.SessionEventArgs) {
defer event.Close()
fmt.Println("Session Stopped (ID=", event.SessionID, ")")
})
task := speechRecognizer.RecognizeOnceAsync()
var outcome speech.SpeechRecognitionOutcome
select {
case outcome = <-task:
case <-time.After(120 * time.Second):
fmt.Println("Timed out")
return "", errors.New("Timed out")
}
defer outcome.Close()
defer os.Remove(path)
if outcome.Error != nil {
fwlog.New(ctx).Info("", "outcomeErr")
return "", outcome.Error
}
return outcome.Result.Text, nil
}