》中简单介绍了 Azure 认知服务中的文本翻译 API,通过这些简单的 REST API 调用就可以轻松地进行机器翻译。如果能在程序中简单的集成语音转文本的功能会不会非常赞!本文我们就介绍如何使用必应的语音识别 API(Bing Speech API) 把语音转换成文本:
SUBSCRIPTIONKEY = ;
。
= =
ShortPhrase 和 LongDictation 两种识别模式。
.dataClient =
,
SUBSCRIPTIONKEY);
SendAudioHelper( (FileStream fileStream =
bytesRead =
[] buffer = [
</span><span style="color: #0000ff">try</span><span style="color: #000000">
{
</span><span style="color: #0000ff">do</span><span style="color: #000000">
{
</span><span style="color: #008000">//</span><span style="color: #008000"> 把文件数据读取到 buffer 中。</span>
bytesRead = fileStream.Read(buffer,<span style="color: #800080">0</span><span style="color: #000000">,buffer.Length);
</span><span style="color: #008000">//</span><span style="color: #008000"> 通过 DataRecognitionClient 类型的实例把语音数据发送到服务端。</span>
<span style="color: #0000ff">this</span><span style="color: #000000">.dataClient.SendAudio(buffer,bytesRead);
}
</span><span style="color: #0000ff">while</span> (bytesRead > <span style="color: #800080">0</span><span style="color: #000000">);
}
</span><span style="color: #0000ff">finally</span><span style="color: #000000">
{
</span><span style="color: #008000">//</span><span style="color: #008000"> 告诉服务端语音数据已经传送完了。</span>
<span style="color: #0000ff">this</span><span style="color: #000000">.dataClient.EndAudio();
}
}
}
--- 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
(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?"
查看详细的语言支持列表。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。