Open jiangying000 opened 1 year ago
code run with go run main.go env is set, and libs installed
go run main.go
package main import ( "fmt" "os" "time" "github.com/Microsoft/cognitive-services-speech-sdk-go/audio" "github.com/Microsoft/cognitive-services-speech-sdk-go/speech" ) func sessionStartedHandler(event speech.SessionEventArgs) { defer event.Close() fmt.Println("Session Started (ID=", event.SessionID, ")") } func sessionStoppedHandler(event speech.SessionEventArgs) { defer event.Close() fmt.Println("Session Stopped (ID=", event.SessionID, ")") } func recognizingHandler(event speech.SpeechRecognitionEventArgs) { defer event.Close() fmt.Println("Recognizing:", event.Result.Text) } func recognizedHandler(event speech.SpeechRecognitionEventArgs) { defer event.Close() fmt.Println("Recognized:", event.Result.Text) } func cancelledHandler(event speech.SpeechRecognitionCanceledEventArgs) { defer event.Close() fmt.Println("Received a cancellation: ", event.ErrorDetails) fmt.Println("Did you set the speech resource key and region values?") } func main() { fmt.Println("startx") speechKey := os.Getenv("SPEECH_KEY") speechRegion := os.Getenv("SPEECH_REGION") // speechKey := "e73873c79fe84132b8fbadb784428ef6" // file := "./ch_m.wav" file := "./OSR_us_000_0010_8k.wav" audioConfig, err := audio.NewAudioConfigFromWavFileInput(file) if err != nil { fmt.Println("Got an error1: ", err) return } defer audioConfig.Close() config, err := speech.NewSpeechConfigFromSubscription(speechKey, speechRegion) if err != nil { fmt.Println("Got an error:2 ", err) return } defer config.Close() speechRecognizer, err := speech.NewSpeechRecognizerFromConfig(config, audioConfig) if err != nil { fmt.Println("Got an error:3 ", err) return } defer speechRecognizer.Close() speechRecognizer.SessionStarted(sessionStartedHandler) speechRecognizer.SessionStopped(sessionStoppedHandler) speechRecognizer.Recognizing(recognizingHandler) speechRecognizer.Recognized(recognizedHandler) speechRecognizer.Canceled(cancelledHandler) task := speechRecognizer.RecognizeOnceAsync() var outcome speech.SpeechRecognitionOutcome select { case outcome = <-task: fmt.Println("got", outcome) case <-time.After(30 * time.Second): fmt.Println("Timed out") return } fmt.Println("selected") defer outcome.Close() if outcome.Error != nil { fmt.Println("Got an error: ", outcome.Error) } fmt.Println("Got a recognition!") fmt.Println(outcome) fmt.Println(outcome.Result) fmt.Println(outcome.Result.Text) // fmt.Println(outcome.Result.Reason) // fmt.Println(outcome.Result.Text) }
output is
startx Session Started (ID= ff0bfbd222394d89866cc2adc5ff0d94 ) Timed out
but curl success:
turned out to be network issue
happens again, java sdk is ok on same machine.
update: java demo takes 2-3s, while go demo takes 32s to transcript same 33s wav file on same server
code run with
go run main.go
env is set, and libs installedoutput is
but curl success: