0
votes

I am building an android app by integrating IBM Speech-To-Text service in it and there first I am recording audio and saving it to device and then passing for conversion but while passing my audio , I am getting error as "unable to transcode data stream audio/wav -> audio/x-float-array" and I tried to give different format of audio too but getting same error for every format. Although audio getting save properly and can be listen using music player.So, please help me to get rid of this error.

Here First I recording audio using MediaRecorder and then saving it to device and then sending it for conversation but getting error and I tried using every possible audio format

fileName = getExternalCacheDir().getAbsolutePath() + "/" + "examples.wav";
    try {
                        RecognizeOptions recognizeOptions = new RecognizeOptions.Builder()
                                .audio(new FileInputStream(fileName))
                                .contentType("audio/wav")
                                .model("en-US_BroadbandModel")
                                .build();

                        BaseRecognizeCallback baseRecognizeCallback =
                                new BaseRecognizeCallback() {

                                    @Override
                                    public void onTranscription
                                            (SpeechRecognitionResults speechRecognitionResults) {
                                        System.out.println(speechRecognitionResults);
                                    }

                                    @Override
                                    public void onConnected() {
                                    }

                                    @Override
                                    public void onError(Exception e) {
                                        Log.i("Error", e.getMessage());
                                        enableMicButton();
                                    }

                                    @Override
                                    public void onDisconnected() {
                                        enableMicButton();
                                    }

                                    @Override
                                    public void onInactivityTimeout(RuntimeException runtimeException) {

                                    }

                                    @Override
                                    public void onListening() {

                                    }

                                    @Override
                                    public void onTranscriptionComplete() {

                                    }


                                };

                        speechToText.recognizeUsingWebSocket(recognizeOptions,
                                baseRecognizeCallback);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
               
1

1 Answers

0
votes

If you are using watson-developer-cloud Java SDK, here's an example that passes the right HTTPMediaType

FileInputStream audio = new FileInputStream("src/test/resources/speech_to_text/sample1.wav");

    RecognizeOptions options =
        new RecognizeOptions.Builder()
            .audio(audio)
            .interimResults(true)
            .contentType(HttpMediaType.AUDIO_WAV)
            .build();

    service.recognizeUsingWebSocket(
        options,
        new BaseRecognizeCallback() {
          @Override
          public void onTranscription(SpeechRecognitionResults speechResults) {
            System.out.println(speechResults);
          }

          @Override
          public void onDisconnected() {
            lock.countDown();
          }
        });

You can find the complete example here