Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timed out after session started #90

Open
jiangying000 opened this issue Feb 22, 2023 · 2 comments
Open

Timed out after session started #90

jiangying000 opened this issue Feb 22, 2023 · 2 comments

Comments

@jiangying000
Copy link

code run with go run main.go
env is set, and libs installed

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:
a677fa946dcf9aaa7524a72181f5c4f

@jiangying000
Copy link
Author

jiangying000 commented Feb 22, 2023

turned out to be network issue

@jiangying000
Copy link
Author

jiangying000 commented Feb 23, 2023

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

@jiangying000 jiangying000 reopened this Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant