Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Cannot retrieve verification phrases #1

Closed
cgero-eth opened this issue Aug 22, 2016 · 3 comments
Closed

Cannot retrieve verification phrases #1

cgero-eth opened this issue Aug 22, 2016 · 3 comments
Assignees

Comments

@cgero-eth
Copy link

I started to test this library for android adding it as dependency in the build.gradle file but I get an error on the getPhrases function.

Here is my code:

private void retrieveSupportedPhrases() {
        SpeakerVerificationRestClient restClient = new SpeakerVerificationRestClient(MY_KEY);
        try {
            List<VerificationPhrase> phrases = restClient.getPhrases("en-US");
            for (int i = 0; i < phrases.size(); i++) {
                Log.i(TAG, phrases.get(i).toString());
            }
        } catch (PhrasesException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }

Here is the error:

FATAL EXCEPTION: main
Process: com.mobile.cir.voicerecognition, PID: 1709
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobile.cir.voicerecognition/com.mobile.cir.voicerecognition.activity.EnableVoiceRecognition}: android.os.NetworkOnMainThreadException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1273)
at java.net.InetAddress.lookupHostByName(InetAddress.java:431)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
at java.net.InetAddress.getAllByName(InetAddress.java:215)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:142)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:169)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:124)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:366)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:560)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:492)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:470)
at com.microsoft.cognitive.speakerrecognition.SpeakerVerificationRestClient.getPhrases(SpeakerVerificationRestClient.java:265)
at com.mobile.cir.voicerecognition.activity.EnableVoiceRecognition.retrieveSupportedPhrases(EnableVoiceRecognition.java:85)
at com.mobile.cir.voicerecognition.activity.EnableVoiceRecognition.onCreate(EnableVoiceRecognition.java:77)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
@momohs
Copy link
Member

momohs commented Aug 22, 2016

Hello @RuggeroCino! By looking at your error log, I can see that the exception is a NetworkOnMainThreadException.

Caused by: android.os.NetworkOnMainThreadException

Android does not allow a user to perform network operations from the main thread. Therefore, you have to call the Speaker Recognition SDK asynchronously. One of the ways to do so is using the AsyncTask. You can wrap the getPhrases call in an AsyncTask to avoid this error.

@momohs momohs self-assigned this Aug 22, 2016
@cgero-eth
Copy link
Author

I tried to use the AsyncTask and it works, thank you.

@momohs
Copy link
Member

momohs commented Aug 24, 2016

Great! Thanks for the update @RuggeroCino! I'll close this issue for now, please feel free to re-open if you have any further questions.

@momohs momohs closed this as completed Aug 24, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants