在我的代码中(如下),当我通过STT处理它时,它只给我整个音频的第一个字母/单词。
音频有“ A B C D E F”
我想念什么?
Imports Microsoft.CognitiveServices.Speech
Imports Microsoft.CognitiveServices.Speech.SpeechConfig
Imports Microsoft.CognitiveServices.Speech.Audio
Module Module1
Sub Main()
Dim SpeechConfig As SpeechConfig = FromSubscription("<CHANGED>", "eastus")
Dim audioConfig As Audio.AudioConfig = Audio.AudioConfig.FromWavFileInput("<CHANGED>.wav")
SpeechConfig.OutputFormat = Microsoft.CognitiveServices.Speech.OutputFormat.Detailed
Dim recognizer As New SpeechRecognizer(SpeechConfig, audioConfig)
Dim result = recognizer.RecognizeOnceAsync().Result
Select Case result.Reason
Case ResultReason.RecognizedSpeech
Console.WriteLine($"RECOGNIZED: Text={result.Text}")
Console.WriteLine($" Intent not recognized.")
Case ResultReason.NoMatch
Console.WriteLine($"NOMATCH: Speech could not be recognized.")
Case ResultReason.Canceled
Dim cancellation = CancellationDetails.FromResult(result)
Console.WriteLine($"CANCELED: Reason={cancellation.Reason}")
If cancellation.Reason = CancellationReason.[Error] Then
Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}")
Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}")
Console.WriteLine($"CANCELED: Did you update the subscription info?")
End If
End Select
End Sub
End Module
您可以在github上下载音频文件 https://github.com/ullfindsmit/StackOverflowAssets/blob/master/abcdef.wav
此外,如果您知道在哪里可以获得更详细的STT数据,我将不胜感激。 我正在寻找的东西就像一个JSON输出,其中显示开始时间和结束时间以及单词和/或句子。
非常感谢您的帮助。
更新 所以异步处理程序由于某种原因对我不起作用 但是,以下代码确实如此
While True
Dim result = recognizer.RecognizeOnceAsync().Result
Select Case result.Reason
Case ResultReason.RecognizedSpeech
Console.WriteLine($"RECOGNIZED: Text={result.Text}")
Console.WriteLine($" Intent not recognized.")
Case ResultReason.NoMatch
Console.WriteLine($"NOMATCH: Speech could not be recognized.")
Case ResultReason.Canceled
Dim cancellation = CancellationDetails.FromResult(result)
Console.WriteLine($"CANCELED: Reason={cancellation.Reason}")
If cancellation.Reason = CancellationReason.[Error] Then
Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}")
Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}")
Console.WriteLine($"CANCELED: Did you update the subscription info?")
End If
Exit While
End Select
End While
答案 0 :(得分:1)
RecognizeOnceAsync
方法将仅识别“一次” ...包含在音频数据文件中的第一个“话语/短语”。如果您想识别多个词组,则可以执行以下两项操作之一:
重复调用RecognizeOnceAsync
...在识别出最后一个短语之后,对该方法的下一次调用将返回将result.Reason
设置为Canceled
的结果。
从使用RecognizeOnceAsync
切换为使用StartContinuousRecognitionAsync
,并将事件处理程序挂接到Recognizing
事件上。通过事件回调,您可以通过检查传递的SpeechRecognitionEventArgs
来查看结果,如下所示:e.Result
...
通过运行语音CLI,您可以看到这两种行为:
spx recognize --once+ --key YOUR-KEY --region YOUR-REGION --file "https://github.com/ullfindsmit/StackOverflowAssets/blob/master/abcdef.wav"
spx recognize --continuous --key YOUR-KEY --region YOUR-REGION --file "https://github.com/ullfindsmit/StackOverflowAssets/blob/master/abcdef.wav"
您可以在此处下载语音CLI:https://aka.ms/speech/spx-zips.zip