Azure Speech SDK使用golang从流中将语音转换为文本

uxhixvfz  于 12个月前  发布在  Go
关注(0)|答案(1)|浏览(119)

当使用Azure Speech SDK Speech到golang中的文本时。我想使用流中的数据,但输出超时。如何修复它?

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
    }

字符串

uelo1irk

uelo1irk1#

尝试使用超时设置修改代码。

// ... (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)

字符串

相关问题