Azure Speech SDK Speech to text from stream using golang

107 Views Asked by At

when using Azure Speech SDK Speech to text in golang. I want to use data from stream but output timeout. how to fix it?

base64Data := "xxxx"
audioBytes, err := base64.StdEncoding.DecodeString(baseData)
    if err != nil {
        panic(err)
    }
//input stream
audioInputStream, err2 := audio.CreatePushAudioInputStream()
    if err2 != nil {
        fmt.Println("CreatePushAudioInputStream err:", err2)
        return
    }

err = audioInputStream.Write(audioBytes[44:])
    if err != nil {
        fmt.Println("write :", err)
        return
    }
audioConfig, err := audio.NewAudioConfigFromStreamInput(audioInputStream)
    if err != nil {
        fmt.Println("Got an error: ", err)
        return
    }

1

There are 1 best solutions below

0
Mohamed Azarudeen Z On

Try this modified code with timeout settings.

// ... (your existing code)

// Set a timeout (example: 30 seconds)
timeout := 30 * time.Second

// Create a speech configuration
speechConfig, err := speechsdk.NewSpeechConfigFromSubscription("<your-subscription-key>", "<your-service-region>")
if err != nil {
    fmt.Println("Error creating speech config: ", err)
    return
}

// Set the service timeout
speechConfig.SetServiceProperty("timeout", timeout.String(), true)

// Create a speech recognizer with the specified settings
speechRecognizer, err := speechsdk.NewSpeechRecognizerFromConfig(speechConfig, audioConfig)
if err != nil {
    fmt.Println("Error creating speech recognizer: ", err)
    return
}

// ... (continue with speech recognition logic)