我正在尝试运行sphinx 4 pre aplha的对话框演示,但它给出了错误。
我正在创建一个实时语音应用程序。
我使用maven导入了这个项目,并遵循了关于堆栈溢出的指南:https://stackoverflow.com/a/25963020/2653162
该错误说明有关16 khz和通道为单声道的问题。所以很明显,这是关于采样的东西。也是关于麦克风的。
我查看了如何将麦克风设置更改为16 khz和16位,但在windows7中没有此选项。

问题是,HelloWorld和对话框演示在sphinx4 1.06测试版中运行良好,但在我尝试最新版本后,它给出了以下错误:
Exception in thread "main" java.lang.IllegalStateException: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 16000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian not supported.
at edu.cmu.sphinx.api.Microphone.<init>(Microphone.java:38)
at edu.cmu.sphinx.api.SpeechSourceProvider.getMicrophone(SpeechSourceProvider.java:18)
at edu.cmu.sphinx.api.LiveSpeechRecognizer.<init>(LiveSpeechRecognizer.java:34)
at edu.cmu.sphinx.demo.dialog.Dialog.main(Dialog.java:145)
Caused by: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 16000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian not supported.
at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDevice.java:513)
at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:121)
at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:413)
at edu.cmu.sphinx.api.Microphone.<init>(Microphone.java:36)
... 3 more我不知道该怎么解决这个问题。
发布于 2015-12-27 20:33:50
如果您修改SpeechSourceProvider以返回一个常量麦克风引用,它将不会尝试创建多个麦克风引用,而这正是问题的根源。
public class SpeechSourceProvider {
private static final Microphone mic = new Microphone(16000, 16, true, false);
Microphone getMicrophone() {
return mic;
}
}这里的问题是,您不希望多个线程尝试访问单个资源,但对于演示,识别器会根据需要停止和启动,这样它们就不会都争用麦克风。
发布于 2016-03-31 03:00:04
aetherwalker的答案对我很有效--更详细地说,我用自己的实现重写了以下文件,其中我只更改了使用的SpeechSourceProvider:
第一个是AbstractSpeechRecognizer:
public class MaxAbstractSpeechRecognizer {
protected final Context context;
protected final Recognizer recognizer;
protected ClusteredDensityFileData clusters;
protected final MaxSpeechSourceProvider speechSourceProvider;
/**
* Constructs recognizer object using provided configuration.
* @param configuration initial configuration
* @throws IOException if IO went wrong
*/
public MaxAbstractSpeechRecognizer(Configuration configuration)
throws IOException
{
this(new Context(configuration));
}
protected MaxAbstractSpeechRecognizer(Context context) throws IOException {
this.context = context;
recognizer = context.getInstance(Recognizer.class);
speechSourceProvider = new MaxSpeechSourceProvider();
} .......................,然后是LiveSpeechRecognizer:
public class MaxLiveSpeechRecognizer extends MaxAbstractSpeechRecognizer {
private final Microphone microphone;
/**
* Constructs new live recognition object.
*
* @param configuration common configuration
* @throws IOException if model IO went wrong
*/
public MaxLiveSpeechRecognizer(Configuration configuration) throws IOException
{
super(configuration);
microphone = speechSourceProvider.getMicrophone();
context.getInstance(StreamDataSource.class)
.setInputStream(microphone.getStream());
}......................和最后但并非最不重要的SpeechSourceProvider:
import edu.cmu.sphinx.api.Microphone;
public class MaxSpeechSourceProvider {
private static final Microphone mic = new Microphone(16000, 16, true, false);
Microphone getMicrophone() {
return mic;
}
}发布于 2020-02-19 17:04:18
对我来说,这个改变的问题是,只要我在cmusphinx的上下文中,这行代码就可以被多次重用。但是如果我开始重复使用麦克风来做其他工作(比如录音),它是不可用的!
我看到流在麦克风类中是打开的,但从来没有关闭过!
因此,首先我在类Microphone中将以下属性从静态更改为动态:
private TargetDataLine line;
private InputStream inputStream;在我更改了在行之前关闭流的方法stopRecording之后:
/**
* close the stream and line
*/
public void stopRecording() {
if (inputStream != null )
try {
inputStream.close();
} catch (IOException e) {
throw new IllegalStateException(e);
}
line.stop();}
现在没有更多的改变(类SpeechSourceProvider是原始的),我可以选择为cmupsphinx和另一个录制任务重用麦克风。
https://stackoverflow.com/questions/29121188
复制相似问题