Input for Pocketsphinx on Android

2020-06-28 02:28发布

I make a demo for speech recognize to text. I have just built the demo Building Pocketsphinx On Android and it work well. But my problem is how to make input from an audio file, not from real time speaking. Any idea to solve it? Thanks.

2条回答
祖国的老花朵
2楼-- · 2020-06-28 03:03

You can use Pocketsphinx API to process any binary data, including binary data read from file. You only need to make sure that data is in the required format. Once you read the binary data into the buffer of type short[] you can process it using pocketsphinx API calls:

import edu.cmu.pocketsphinx.pocketsphinx;

Pocketsphinx ps = new Decoder(....)
ps.processRaw(buf, buf.length, false, false);

After all data is processed you can retrieve the result

Hypothesis hyp = pocketsphinx.getHyp();
System.out.println(hyp.getHypstr())

For more details see the Pocketsphinx part of the CMUSphinx tutorial

查看更多
Fickle 薄情
3楼-- · 2020-06-28 03:07

Although a little late in the day, hope it might be of help to someone else looking to address similar requirements. Have a look at the following code in SpeechRecognizerclass in particular at Declaring AudioRecord object AudioRecord recorder = new AudioRecord( AudioSource.VOICE_RECOGNITION, sampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize * 2); Creating another class like SpeechRecognizer, you could choose any of the audio sources supported by MediaRecord

查看更多
登录 后发表回答