日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

正在等待语音服务器回应,Python如何突破正在等待服务器响应的阻塞生成器?

發布時間:2024/7/23 python 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 正在等待语音服务器回应,Python如何突破正在等待服务器响应的阻塞生成器? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我想添加一個錯誤處理程序,它可以在出現internet連接問題時停止轉錄過程。我創建了一個連接監視器線程,每隔幾秒鐘檢查一次internet連接,并將設置一個標志isConnectionError = True。在

我設法停止音頻錄制生成器進程,但無法停止另一個阻止并等待服務器發送響應消息的生成器進程:def listen_print_loop(responses):

"""Iterates through server responses and prints them.

The responses passed is a generator that will block until a response

is provided by the server.

Each response may contain multiple results, and each result may contain

multiple alternatives; for details, see . Here we

print only the transcription for the top alternative of the top result.

In this case, responses are provided for interim results as well. If the

response is an interim one, print a line feed at the end of it, to allow

the next result to overwrite it, until the response is a final one. For the

final one, print a newline to preserve the finalized transcription.

"""

num_chars_printed = 0

for response in responses:

if not response.results:

continue

# The `results` list is consecutive. For streaming, we only care about

# the first result being considered, since once it's `is_final`, it

# moves on to considering the next utterance.

result = response.results[0]

if not result.alternatives:

continue

# Display the transcription of the top alternative.

transcript = result.alternatives[0].transcript

# Display interim results, but with a carriage return at the end of the

# line, so subsequent lines will overwrite them.

#

# If the previous result was longer than this one, we need to print

# some extra spaces to overwrite the previous result

overwrite_chars = ' ' * (num_chars_printed - len(transcript))

if not result.is_final:

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(r'\b(exit|quit)\b', transcript, re.I):

print('Exiting..')

break

num_chars_printed = 0

總結

以上是生活随笔為你收集整理的正在等待语音服务器回应,Python如何突破正在等待服务器响应的阻塞生成器?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。