alphacep / vosk-android-demo

Offline speech recognition for Android with Vosk library.
Apache License 2.0
714 stars 187 forks source link

Problem reading .3gp files #180

Open noellemorris opened 2 years ago

noellemorris commented 2 years ago

Hi,

I'm attempting to adapt the File recognition code to files I record with Android's MediaRecorder class, and I'm having trouble getting it to work with code something like the following:

File outputDir = application.getFilesDir();
String fileName = "TEST.3gp" 

File audioFile = new File(outputDir + File.separator + fileName);

if (!audioFile.exists()) return;

Then I pass it to the sample code's recognizeFile method with:

InputStream ais = new FileInputStream(audioFile);

But the results in my callbacks are always empty. Is .3gp not supported by SpeechStreamService? If not, what file formats are supported? Or is there something else I'm doing wrong? (I never get an IOException, just empty hypothesis strings in the callbacks.)

nshmyrev commented 2 years ago

Is .3gp not supported by SpeechStreamService?

No, you have to transcode.

If not, what file formats are supported?

Only raw PCM data.

noellemorris commented 2 years ago

Thank you for the quick response! I do have some additional questions:

If not, what file formats are supported?

Only raw PCM data.

Could you explain what you mean by this? Because your this sample app uses a .wav from the assets folder:

https://github.com/alphacep/vosk-android-demo/blob/248f40de2449a6185a9e7b3fb9d985aa5221312c/app/src/main/java/org/vosk/demo/VoskActivity.java#L212-L213

So I'd like to understand why that works, if only raw PCM data is supported.

Thanks!