Azure AI 服务之语音识别

前端之家收集整理的这篇文章主要介绍了Azure AI 服务之语音识别前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

301_0@。

= =

ShortPhrase 和 LongDictation 两种识别模式。支持 15 秒的语音。语音数据被分块发送到服务端,服务端会及时的返回部分的识别结果,所以客户端会收到多个部分结果和一个包含多个 n-best 选项的最终结果。支持最长两分钟的语音。语音数据被分块发送到服务器,根据服务端分辨出的语句间的停顿,客户端会受到多个部分结果和多个最终结果。

代码中我们要通过它们来告诉语音识别 API 执行识别的类型。比如要识别比 15s 短的语音,可以使用 ShortPhrase 模式构建 CreateDataClient 类型的实例:

方法创建 DataRecognitionClient 类型的实例。 .dataClient = ,文件都是英语语音。 SUBSCRIPTIONKEY);

效果,我们必须把音频数据以适当大小的块连续发送给服务端,下面代码中使用的块大小为 1024:

文件的名称 SendAudioHelper( (FileStream fileStream = dio file in wave format,and instead you have just dio coming over bluetooth),then before sending up any dio data,you must first send up an SpeechAudioFormat descriptor to describe dio data via DataRecognitionClient's sendAudioFormat() method. bytesRead = [] buffer = [ </span><span style="color: #0000ff"&gt;try</span><span style="color: #000000"&gt; { </span><span style="color: #0000ff"&gt;do</span><span style="color: #000000"&gt; { </span><span style="color: #008000"&gt;//</span><span style="color: #008000"&gt; 把<a href="/tag/wenjian/" target="_blank" class="keywords">文件</a>数据读取到 buffer 中。</span> bytesRead = fileStream.Read(buffer,<span style="color: #800080"&gt;0</span><span style="color: #000000"&gt;,buffer.Length); </span><span style="color: #008000"&gt;//</span><span style="color: #008000"&gt; 通过 DataRecognitionClient 类型的实例把语音数据发送到服务端。</span> <span style="color: #0000ff"&gt;this</span><span style="color: #000000"&gt;.dataClient.SendAu<a href="/tag/dio/" target="_blank" class="keywords">dio</a>(buffer,bytesRead); } </span><span style="color: #0000ff"&gt;while</span> (bytesRead > <span style="color: #800080"&gt;0</span><span style="color: #000000"&gt;); } </span><span style="color: #0000ff"&gt;finally</span><span style="color: #000000"&gt; { </span><span style="color: #008000"&gt;//</span><span style="color: #008000"&gt; 告诉服务端语音数据已经传送完了。</span> <span style="color: #0000ff"&gt;this</span><span style="color: #000000"&gt;.dataClient.EndAu<a href="/tag/dio/" target="_blank" class="keywords">dio</a>(); } }

}

dio() 方法显式的告诉服务端数据传送结束。

效果。服务器端通过 OnPartialResponseReceived 事件不断把识别的结果发送到客户端。比如 demo 中演示的 ShortPhrase 模式实例,我们会得到下面的中间结果(在上面的输出框中):

--- Partial result received by OnPartialResponseReceivedHandler() --- why

--- Partial result received by OnPartialResponseReceivedHandler() ---
<span style="color: #ff0000">what's

--- Partial result received by OnPartialResponseReceivedHandler() ---
<span style="color: #ff0000">what's the weather

--- Partial result received by OnPartialResponseReceivedHandler() ---
<span style="color: #ff0000">what's the weather like

调用了 EndAudio() 函数。语音识别服务在完成识别后会触发 OnResponseReceived 事件,我们通过下面的函数把结果输出到 UI 中:

输出到 UI。 (e.PhraseResponse.Results.Length == .WriteLine(.WriteLine( ( i = ; i < e.PhraseResponse.Results.Length; i++

--- OnDataShortPhraseResponseReceivedHandler --- ********* Final n-BEST Results ********* [0] Confidence=High,Text="What's the weather like?"

属性,比如我们可以根据 Confidence 属性判断识别的结果是否可靠:

内容和 ShortPhrase 模式类似。更详细的内容请大家直接看代码吧,很简单的。

支持语言

中文支持还是比较全面的,现在支持的所有模式都支持中文。如果你还有其它需求,可以从查看详细的语言支持列表。

猜你在找的Azure相关文章