-
Notifications
You must be signed in to change notification settings - Fork 320
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
I signed it! |
CLAs look good, thanks! |
@PizlaTheDeveloper Thanks for reporting the issue, and working on a fix! I still get this error when running your branch:
starting on the second request. |
if input_audio_file: | ||
audio_source = audio_helpers.WaveSource( | ||
open(input_audio_file, 'rb'), | ||
sample_rate=audio_sample_rate, | ||
sample_width=audio_sample_width | ||
) | ||
else: | ||
audio_source = audio_device = ( | ||
audio_device or audio_helpers.SoundDeviceStream( | ||
audio_source = audio_helpers.SoundDeviceStream( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we don't reuse the same stream for input/output, I think we might be able to get rid of some of the locking happening in conversationstream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe reusing the stream is possible, I didn't understand how it could be reused, but now it is more clear for me :) Sorry, I am Python beginner :)
@@ -138,6 +137,7 @@ def iter_assist_requests(): | |||
logging.info('Transcript of user request: "%s".', | |||
' '.join(r.transcript | |||
for r in resp.speech_results)) | |||
self.conversation_stream.start_playback() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to keep doing this in the same grpc thread from where the stream reading is happening (i.e: at the end of the generator).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the whole problem is that I get data for playback in assist response before the request generator ends, so the playback is not started yet and writing to playback stream gets stuck while waiting to start the playback...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PizlaTheDeveloper yep, but I don't think this will be an issue if we use two different stream as you introduced with d0eb6a3
Can you give a try to 2c63ebc and let me know if it works for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but it doesn't work :(
The generator 'iter_assist_requests' will never stop iterating because it iterates while conversation_stream has data on its input, but there will be always some data if the source stream is running. So the recording will never stop.
I think that the events '_stop_recording' and '_start_playback ' should stay in ConversationStream to be able to signalize stop recording and return empty data to read calling what will end the iteration. Stop recording must be signaled when END_OF_UTTERANCE occurs.
I don't know if I described it correctly :)
I think my previous code was correct :)
Thank you for your interest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generator 'iter_assist_requests' will never stop iterating because it iterates while conversation_stream has data on its input, buend_of_utterancet there will be always some data if the source stream is running. So the recording will never stop.
Makes total sense!
I added an explicit end_of_utterance
event in 187b485 (which I believe is cleaner that tying everything to stop_recording
) let me know what you think!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PizlaTheDeveloper Thanks for digging this out.
Because of https://github.com/grpc/grpc/blob/16316a9fec3a78baf83d96dbdb392e90226bb013/src/python/grpcio/grpc/_channel.py#L682, I was making the assumption that grpc would always exhaust the request generator before ending the iteration of the response, and thought this would always be called:
187b485#diff-7262ae17d2cea4f6cb6c2b5934aaf939L127
But it looks like it's not the case! and that the iteration on self.assistant.Assist
responses can finish before iter_assist_requests
is exhausted. (Maybe @nathanielmanistaatgoogle can shed some light on the expected behavior).
@PizlaTheDeveloper can you give a try at 2dfc868 I added explicit locking to make sure we can safely close the recording stream from the main thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's working like a charm now !!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you review/approve #188 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without reading this whole conversation, so I may be missing some context: yes, it is not the case that exhaustion of the request iterator is guaranteed. If an RPC ends (for whatever reason, successfully or unsuccessfully) before exhaustion of the request iterator, iteration of the request iterator may be stopped. (Or it may be continued! Don't depend on either being the case.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nathanielmanistaatgoogle Thanks for the confirmation! So we really shouldn't perform any cleanup/teardown logic at the end of the iterator :)
Suggesting changes made on pushtotalk.py to be able to use fix-stream #188 by @proppy