Conversation
speech/grpc/transcribe_streaming.py
Outdated
There was a problem hiding this comment.
You can add the audio_stream.stop_stream() back.
|
LGTM other than the single comment I had. |
| if None in data: | ||
| stop = True | ||
| data.remove(None) | ||
| yield b''.join(data) |
There was a problem hiding this comment.
nit: blank line above yield.
speech/grpc/transcribe_streaming.py
Outdated
|
|
||
|
|
||
| def _fill_buffer(audio_stream, buff, chunk, stoprequest): | ||
| def _fill_buffer(buff): |
There was a problem hiding this comment.
Instead of a closure, just use functools.partial:
def audio_stream_callback(buffer, in_data, frame_count, time_info, status_flags):
...
stream_callback=functools.partial(audio_stream_callback, buffer)| def record_audio(rate, chunk): | ||
| """Opens a recording stream in a context manager.""" | ||
| # Create a thread-safe buffer of audio data | ||
| buff = queue.Queue() |
There was a problem hiding this comment.
s/buff/buffer? (throughout)
There was a problem hiding this comment.
I avoided this since buffer is a keyword
There was a problem hiding this comment.
TIL.
(It's a built-in function which means it can be shadowed, like file, but I'm fine if you leave it as buff).
There was a problem hiding this comment.
Yeah, me too. I just avoided it because vim bolded it after I spelled it out, which made me wary :-)
| # the `audio_stream` once it's set. | ||
| stoprequest = threading.Event() | ||
|
|
||
| # For streaming audio from the microphone, there are three threads. |
There was a problem hiding this comment.
are these comments about the number of threads still accurate?
There was a problem hiding this comment.
Yup! It's just that before we were spinning up the buffer-the-audio thread manually, and now pyaudio is doing it for us.
|
@dpebot would you please merge when travis becomes green (presumably with envy)? |
|
Okay! I'll merge when all statuses are green. |
|
@jerjou travis failed here. |
|
Oh right. Tests. |
This lets us avoid spinning up our own thread, and saves some LOC. Tested in OSX and linux.
|
...i mean, now. |
* Add GCS file-like io samples * now with pandas! * change pandas version * add to readme * requests from andrew * lint * canonical command line args * Update storage_fileio_pandas.py * Update storage_fileio_write_read.py
I discovered, while reviewing #635, that pyaudio has an async api.
This lets us avoid spinning up our own thread, and saves some LOC.
Also - since the callback thread will automatically be closed by pyaudio when the stream is closed, we don't have to check
stopaudioin it any longer, which saves us a control object being passed around.Tested in OSX and linux.