我有一个 .wav 文件,其中包含文本“hello” 。
目的是读取.wav文件并取回文本。我通过使用下面的代码将NAudio用于此目的
using (WaveFileReader reader = new WaveFileReader("D:\\test.wav"))
{
byte[] buffer = new byte[reader.Length];
int read = reader.Read(buffer, 0, buffer.Length);
short[] sampleBuffer = new short[read / 2];
System.Buffer.BlockCopy(buffer, 0, sampleBuffer, 0, read);
}
在将数组转换回字符串时,我收到空白文本
var bytes = a.SelectMany(x => BitConverter.GetBytes(x)).ToArray();
var originalText = System.Text.Encoding.Unicode.GetString(bytes);
我想念的是什么?
最佳答案
既然您已经澄清了您的问题(包括评论中的内容),那么它是一个有效的问题,并且有答案!
Microsoft Speech Platform Use WAV File Input for Speech Recognition
该页面上的示例显示使用API输入WAV文件并输出文本,如下所示:
The following are the contents of the grammar FlightDestination.grxml.
<?xml version="1.0" encoding="utf-8"?>
<grammar version="1.0" xml:lang="en-US" mode="voice" root="destination" xmlns="http://www.w3.org/2001/06/grammar" tag-format="semantics/1.0">
<rule id="destination">
<item> I want to fly to </item>
<ruleref uri="#city"/>
</rule>
<rule id="city">
<one-of>
<item> Boston </item>
<item> Madrid </item>
<item> London </item>
</one-of>
</rule>
</grammar>
这似乎正是您要寻找的。
关于c#-4.0 - 如何使用NAudio从Wav文件读取文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34460179/