使用 Sphinx 4 语音识别平台效果不佳
Poor results using Sphinx 4 speech recognition platform
我想开发一个简单的基于 android 的应用程序,其操作如下:
听外面的声音,一旦识别出'Time'这个词,智能手机应该会读出当前时间。
为了实现该目标,我一直在寻找基于 java 的语音识别库,它与 android 平台兼容,并找到了 Sphinix 4 平台。
但是,我尝试在我的 PC 上使用上述库进行试验,但结果很差。 (0% 成功)
我的代码:
public class Main {
public static void main(String[] args) throws Exception {
Configuration configuration = new Configuration();
configuration
.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
configuration
.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
configuration
.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
Microphone micro = new Microphone(44100, 16, true, false);
micro.startRecording();
StreamSpeechRecognizer recognizer = new StreamSpeechRecognizer(
configuration);
// Simple recognition with generic model
recognizer.startRecognition(micro.getStream());
SpeechResult result;
while ((result = recognizer.getResult()) != null) {
System.out.format("Hypothesis: %s\n", result.getHypothesis());
}
recognizer.stopRecognition();
micro.stopRecording();
}
}
我很乐意提出建议。
编辑:
根据下面的建议,我把码率改成了16khz,效果稍微好一点。
但是,将 StreamSpeechRecognizer
更改为 LiveSpeechRecognizer
后,我得到了不受支持的异常:
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 16000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian not supported.
编辑 2:
我只想检测一个词(短语):'Time'。
可能是我使用语音识别的方法有误?
再次感谢。
tutorial 中提供了识别麦克风音频的代码示例。正确的代码使用 LiveSpeechRecognizer。您的代码无法正常工作,因为您在麦克风中使用 44.1khz 采样率,识别器不支持此速率。
另外,sphinx4 在 Android 上 运行 太耗资源了,不可能在那里使用它。 CMUSphinx 项目提供 Pocketsphinx on Android 专门为移动应用程序设计的库。这个库在另一个 tutorial.
中描述
我想通了:
我要找的是 Keyword Spotting,而不是一般的语音识别。
我发现 Pocketsphinx 库非常适合我的需要。
我想开发一个简单的基于 android 的应用程序,其操作如下:
听外面的声音,一旦识别出'Time'这个词,智能手机应该会读出当前时间。
为了实现该目标,我一直在寻找基于 java 的语音识别库,它与 android 平台兼容,并找到了 Sphinix 4 平台。
但是,我尝试在我的 PC 上使用上述库进行试验,但结果很差。 (0% 成功)
我的代码:
public class Main {
public static void main(String[] args) throws Exception {
Configuration configuration = new Configuration();
configuration
.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
configuration
.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
configuration
.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
Microphone micro = new Microphone(44100, 16, true, false);
micro.startRecording();
StreamSpeechRecognizer recognizer = new StreamSpeechRecognizer(
configuration);
// Simple recognition with generic model
recognizer.startRecognition(micro.getStream());
SpeechResult result;
while ((result = recognizer.getResult()) != null) {
System.out.format("Hypothesis: %s\n", result.getHypothesis());
}
recognizer.stopRecognition();
micro.stopRecording();
}
}
我很乐意提出建议。
编辑:
根据下面的建议,我把码率改成了16khz,效果稍微好一点。
但是,将 StreamSpeechRecognizer
更改为 LiveSpeechRecognizer
后,我得到了不受支持的异常:
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 16000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian not supported.
编辑 2:
我只想检测一个词(短语):'Time'。 可能是我使用语音识别的方法有误?
再次感谢。
tutorial 中提供了识别麦克风音频的代码示例。正确的代码使用 LiveSpeechRecognizer。您的代码无法正常工作,因为您在麦克风中使用 44.1khz 采样率,识别器不支持此速率。
另外,sphinx4 在 Android 上 运行 太耗资源了,不可能在那里使用它。 CMUSphinx 项目提供 Pocketsphinx on Android 专门为移动应用程序设计的库。这个库在另一个 tutorial.
中描述我想通了:
我要找的是 Keyword Spotting,而不是一般的语音识别。
我发现 Pocketsphinx 库非常适合我的需要。