Page 1134 - 3-2
P. 1134
overwrite_chars = ' ' * max(0, num_chars_printed - len(transcript))
# 특정한 말로 종료시 음성 인식 종료
if not (re.search(u' 어때', transcript, re.I) or re.search(u' 줘', transcript, re.I) or re.search(u'
있니', transcript, re.I) or re.search(u' 꺼', transcript, re.I) or re.search(u' 켜', transcript, re.I)):
sys.stdout.write(transcript + overwrite_chars + '\r')
sys.stdout.flush()
num_chars_printed = len(transcript)
else:
print(transcript + overwrite_chars)
# Exit recognition if any of the transcribed phrases could be
# one of our keywords.
if re.search(u'exit', transcript, re.I):
print(' 음성인식이 종료됩니다...')
break
word=transcript
break
def send_transcribe():
service = cloud_speech_pb2.SpeechStub(
make_channel('speech.googleapis.com', 443))
# For streaming audio from the microphone, there are three threads.
# First, a thread that collects audio data as it comes in
with record_audio(RATE, CHUNK) as buffered_audio_data:
# Second, a thread that sends requests with that data
requests = request_stream(buffered_audio_data, RATE)
# Third, a thread that listens for transcription responses
recognize_stream = service.StreamingRecognize(
requests, DEADLINE_SECS)
# Exit things cleanly on interrupt
signal.signal(signal.SIGINT, lambda *_: recognize_stream.cancel())
# Now, put the transcription responses to use.
try:
listen_print_loop(recognize_stream)
recognize_stream.cancel()
except grpc.RpcError as e:
- 1134 -