Search code examples
javaandroidibm-cloudspeech-to-textibm-watson

SpeechToText IBM Watson ExceptionInInitializerError


Im having problem with testing IBM Watson SpeechToText Api.

  SpeechToText service = new SpeechToText();
        service.setUsernameAndPassword("<UserName>", "<Password>");

        File audio = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
                +MEDIA_FOLDER+"/myaudio.amr");

        SpeechResults transcript = service.recognize(audio).execute();
        System.out.println(transcript);

im getting java.lang.ExceptionInInitializerError error at SpeechToText service = new SpeechToText(); line

Error

java.lang.ExceptionInInitializerError
at com.fexcon.voicetotext.MainActivity.processAudioIBM(MainActivity.java:190)
at com.fexcon.voicetotext.MainActivity$4.onClick(MainActivity.java:100)
at android.view.View.performClick(View.java:5184)
at android.view.View$PerformClick.run(View.java:20910)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Caused by: java.lang.IllegalArgumentException: Unknown pattern character 'X'
at java.text.SimpleDateFormat.validatePatternCharacter(SimpleDateFormat.java:314)
at java.text.SimpleDateFormat.validatePattern(SimpleDateFormat.java:303)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:356)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:249)
at com.ibm.watson.developer_cloud.util.DateDeserializer.<init>(DateDeserializer.java:52)
at com.ibm.watson.developer_cloud.util.GsonSingleton.registerTypeAdapters(GsonSingleton.java:53)
at com.ibm.watson.developer_cloud.util.GsonSingleton.createGson(GsonSingleton.java:42)
at com.ibm.watson.developer_cloud.util.GsonSingleton.getGsonWithoutPrettyPrinting(GsonSingleton.java:76)
at com.ibm.watson.developer_cloud.speech_to_text.v1.SpeechToText.<clinit>(SpeechToText.java:119)
at com.fexcon.voicetotext.MainActivity.processAudioIBM(MainActivity.java:190) 
at com.fexcon.voicetotext.MainActivity$4.onClick(MainActivity.java:100) 
at android.view.View.performClick(View.java:5184) 
at android.view.View$PerformClick.run(View.java:20910) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:145) 
at android.app.ActivityThread.main(ActivityThread.java:5942) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195) 

Solution

  • Update

    It happend only to lower level SDK devices. once i added latest speech-to-text library, it solved. 'com.ibm.watson.developer_cloud:speech-to-text:3.8.1-SNAPSHOT' insted of 'com.ibm.watson.developer_cloud:speech-to-text:3.8.0' Info.


    Today i started another android project from scratch and didnt get that above runtime exception. and i have managed to get the text out of wave file.

    Example :

     final SpeechToText service = new SpeechToText();
                service.setUsernameAndPassword("<YourUsername>", "<Password>");
    
                final File audio = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/about_time.wav");
    
                final RecognizeOptions options = new RecognizeOptions.Builder()
                        .continuous(false)
                        .model("en-US_NarrowbandModel")
                        .interimResults(true)
                        .contentType(HttpMediaType.AUDIO_WAV)
                        .build();
    
    
    
                new Thread(new Runnable() {
                    public void run() {
                        SpeechResults transcript = service.recognize(audio, options).execute();
                        System.out.println(transcript);
                    }
                }).start();