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.
问题:
回答1:
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
回答2:
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 SpeechRecognizer
class 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