watson-developer-cloud / java-sdk

:1st_place_medal: Java SDK to use the IBM Watson services.
http://watson-developer-cloud.github.io/java-sdk/
Apache License 2.0
593 stars 532 forks source link

[STT]Audio is not a valid audio file?! #133

Closed birkanu closed 8 years ago

birkanu commented 8 years ago

Hi,

I am trying to run SpeechToTextExample.java with the sample wav file you provide. However, I have been getting the following error:

Exception in thread "main" java.lang.IllegalArgumentException: audio is not a valid audio file
    at com.ibm.watson.developer_cloud.util.Validate.isTrue(Validate.java:40)
    at com.ibm.watson.developer_cloud.speech_to_text.v1.SpeechToText.recognize(SpeechToText.java:231)
    at com.ibm.watson.developer_cloud.speech_to_text.v1.SpeechToText.recognize(SpeechToText.java:218)
    at samples.IBMSpeechRecognitionSample.main(IBMSpeechRecognitionSample.java:17)

Does anyone know why this might be happening?

Thanks!

birkanu commented 8 years ago

I also tried a flac file, but that did not work either.

birkanu commented 8 years ago

Unfortunately, trying to transcript using HTTP or a WebSocket also fails with the same error.

germanattanasio commented 8 years ago

When calling the recognize you need to specify the audio format and it should be a valid media type.

I just tested the example below and it's working:

    final SpeechToText service = new SpeechToText();
    service.setUsernameAndPassword("<username>", "<password>");

    final File audio = new File("src/test/resources/sample1.wav");
    final SpeechResults transcript = service.recognize(audio, HttpMediaType.AUDIO_WAV);

    System.out.println(transcript);

Make sure that you send a valid contentType link audio/wav

birkanu commented 8 years ago

It's interesting because I used the exact same example with sample1.wav file, and I got the error I mentioned above. However, the same file worked when I used it in a cURL command.

germanattanasio commented 8 years ago

So the request never gets to the server because the contentType is incorrect. Try to use the example I pasted above and let me know if it doesn't work.

I've opened an issue (#135) to recognize the content type automatically based on the file extension.

birkanu commented 8 years ago

The example works now. Turns out the path for my wav file was incorrect.

jsstylos commented 8 years ago

@germanattanasio: Can we detect InputStreams that represent missing files and give a more useful error message?

germanattanasio commented 8 years ago

we are returning "audio is not a valid audio file". I guess I could say "file not found"

germanattanasio commented 8 years ago

what about "audio file is null or does not exist"

jsstylos commented 8 years ago

The point would be to have two separate error messages, assuming we can differentiate between them.

gamal-ahmed commented 8 years ago

i don't know why you are keeping it to show "audio is not a valid audio file" you can separate messages

germanattanasio commented 8 years ago

@gamal-ahmed I'm doing 2 checks.

  1. checking if the file is null or doesn't exists
  2. checking the file extension to make sure it's a valid audio file: .wav, .flac, etc..