c#-4.0 - 如何使用NAudio从Wav文件读取文本?

标签 c#-4.0 audio naudio

我有一个 .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/

相关文章:

c# - 强签名 NAudio.dll

multithreading - 如何在没有主线程等待的情况下从长时间运行的后台任务引发异常

xcode - 从应用程序播放音频,即使它在后台

c++ - C++的新手,想知道如何使用VS Code 2019播放音频文件

c# - BufferedWaveProvider 在 Unity 中不起作用

c# - 实时 wasapi 捕获错误(来自声卡)操作和播放

c# - 创建通用类 C#

c# - 解析数学表达式

c# - 如何设置两个单元格之间的空间

c# - 停止在线程中播放音乐