Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speech to Text: OggOpusEncoder hanging on close after Inactivity Timeout #50

Open
smccants opened this issue Mar 13, 2018 · 5 comments
Open
Assignees
Labels

Comments

@smccants
Copy link
Contributor

I'm working on a sample Speech-to-text Android App that will timeout after a certain amount of inactivity from the speaker. For testing purposes, I set the timeout at 1 second. However, there seems to be a race condition (which I reproduced in the example by setting the inactivity timeout to 1 second) that causes the MicrophoneHelper to hang on closing.

The hang occurs in MicrophoneCaptureThread.run() line 110 - encoder.close() call. I'm not quite sure what is hanging it up, but if you toggle the microphone and then let it timeout after one or two attempts it will fail this way. The final hang is in MicrophoneInputStream.consume(byte[]).

Here is the link to the sample application I used: https://github.com/watson-developer-cloud/android-sdk/blob/master/example/src/main/java/com/ibm/watson/developer_cloud/android/myapplication/MainActivity.java

The only change I made was to getRecognizeOptions() where I changed the timeout from 2000 to 1.

@smccants
Copy link
Contributor Author

Workaround: I use a timer in my app which calls "microphoneHelper.closeInputStream();". This seems to avoid the problem.

@smccants
Copy link
Contributor Author

@lpatino10 lpatino10 self-assigned this Mar 14, 2018
@lpatino10 lpatino10 added the bug label Mar 14, 2018
@lpatino10
Copy link
Contributor

Hey @smccants, thanks for bringing this issue up. I've assigned myself to take a look at this as soon as I get some time and I'll report back with any findings.

@smccants
Copy link
Contributor Author

I think I'm running into a slightly different flavor of this problem. Any update on when it might be fixed?

@smccants
Copy link
Contributor Author

It looks like the hang is a result of this thread never exiting:

"Thread-5@5044" prio=5 tid=0x5c7 nid=NA waiting
  java.lang.Thread.State: WAITING
	 blocks Thread-5@5044
	  at java.lang.Object.wait(Object.java:-1)
	  at java.lang.Object.wait(Object.java:407)
	  at java.io.PipedInputStream.awaitSpace(PipedInputStream.java:280)
	  at java.io.PipedInputStream.receive(PipedInputStream.java:238)
	  - locked <0x15d5> (a java.io.PipedInputStream)
	  at java.io.PipedOutputStream.write(PipedOutputStream.java:149)
	  at java.io.OutputStream.write(OutputStream.java:75)
	  at com.ibm.watson.developer_cloud.android.library.audio.MicrophoneInputStream.consume(MicrophoneInputStream.java:142)
	  at com.ibm.watson.developer_cloud.android.library.audio.opus.OpusWriter.write(OpusWriter.java:236)
	  at com.ibm.watson.developer_cloud.android.library.audio.opus.OpusWriter.flush(OpusWriter.java:209)
	  at com.ibm.watson.developer_cloud.android.library.audio.opus.OpusWriter.writePacket(OpusWriter.java:184)
	  at com.ibm.watson.developer_cloud.android.library.audio.opus.OggOpusEnc.encodeAndWrite(OggOpusEnc.java:116)
	  at com.ibm.watson.developer_cloud.android.library.audio.MicrophoneCaptureThread.run(MicrophoneCaptureThread.java:99)

While this thread is hung, the main thread is in a spin loop waiting for it:

"main@4487" prio=5 tid=0x1 nid=NA sleeping
  java.lang.Thread.State: TIMED_WAITING
	 blocks main@4487
	  at java.lang.Thread.sleep(Thread.java:-1)
	  at java.lang.Thread.sleep(Thread.java:371)
	  - locked <0x15bb> (a java.lang.Object)
	  at java.lang.Thread.sleep(Thread.java:313)
	  at com.ibm.watson.developer_cloud.android.library.audio.MicrophoneCaptureThread.end(MicrophoneCaptureThread.java:126)
	  at com.ibm.watson.developer_cloud.android.library.audio.MicrophoneInputStream.close(MicrophoneInputStream.java:109)
	  at com.ibm.watson.developer_cloud.android.library.audio.MicrophoneHelper.closeInputStream(MicrophoneHelper.java:61)
	  at com.hcs.android.watsonspeech.MainActivity.turnOffSpeechRecognition(MainActivity.java:96)
	  at com.hcs.android.watsonspeech.MainActivity$1.onCheckedChanged(MainActivity.java:51)
	  at android.widget.CompoundButton.setChecked(CompoundButton.java:166)
	  at android.widget.Switch.setChecked(Switch.java:1127)
	  at com.hcs.android.watsonspeech.MainActivity$5.run(MainActivity.java:133)
	  at android.os.Handler.handleCallback(Handler.java:751)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants