Google cloud platform 谷歌云语音到文本API中的音频超时错误

Google cloud platform 谷歌云语音到文本API中的音频超时错误,google-cloud-platform,speech-recognition,session-timeout,Google Cloud Platform,Speech Recognition,Session Timeout,我的目标是让我的jarvis一直在听,当我打招呼时它就会激活。我了解到谷歌云语音到文本API的监听时间不超过60秒,但后来我发现了这个不太出名的链接,它可以无限长地监听。github脚本的作者说,他玩了一个技巧,让脚本在60秒后刷新,这样程序就不会崩溃 以下是修改后的版本,因为我想让它回答我的问题,然后是“你好”,而不是一直回答我。现在,如果我问我的Jarvis,一个回答时间超过60秒且没有时间刷新的问题,程序会崩溃:( 您可以在不同线程中识别后调用函数。例如: new_thread = Th

我的目标是让我的jarvis一直在听,当我打招呼时它就会激活。我了解到谷歌云语音到文本API的监听时间不超过60秒,但后来我发现了这个不太出名的链接,它可以无限长地监听。github脚本的作者说,他玩了一个技巧,让脚本在60秒后刷新,这样程序就不会崩溃

以下是修改后的版本,因为我想让它回答我的问题,然后是“你好”,而不是一直回答我。现在,如果我问我的Jarvis,一个回答时间超过60秒且没有时间刷新的问题,程序会崩溃:(


您可以在不同线程中识别后调用函数。例如:

new_thread = Thread(target=music.play)
new_thread.daemon = True # Not always needed, read more about daemon property
new_thread.start()
with mic_manager as stream:
    while not stream.closed:
        try:
            audio_generator = stream.generator()
            requests = (speech.types.StreamingRecognizeRequest(
                audio_content=content)
                for content in audio_generator)

            responses = client.streaming_recognize(streaming_config,
                                                   requests)
            # Now, put the transcription responses to use.
            listen_print_loop(responses, stream, code)
        except BaseException as e:
            print("Exception occurred - {}".format(str(e)))
或者,如果您只是想防止异常,则可以始终使用try/except。例如:

new_thread = Thread(target=music.play)
new_thread.daemon = True # Not always needed, read more about daemon property
new_thread.start()
with mic_manager as stream:
    while not stream.closed:
        try:
            audio_generator = stream.generator()
            requests = (speech.types.StreamingRecognizeRequest(
                audio_content=content)
                for content in audio_generator)

            responses = client.streaming_recognize(streaming_config,
                                                   requests)
            # Now, put the transcription responses to use.
            listen_print_loop(responses, stream, code)
        except BaseException as e:
            print("Exception occurred - {}".format(str(e)))

您可以在不同线程中识别后调用函数。例如:

new_thread = Thread(target=music.play)
new_thread.daemon = True # Not always needed, read more about daemon property
new_thread.start()
with mic_manager as stream:
    while not stream.closed:
        try:
            audio_generator = stream.generator()
            requests = (speech.types.StreamingRecognizeRequest(
                audio_content=content)
                for content in audio_generator)

            responses = client.streaming_recognize(streaming_config,
                                                   requests)
            # Now, put the transcription responses to use.
            listen_print_loop(responses, stream, code)
        except BaseException as e:
            print("Exception occurred - {}".format(str(e)))
或者,如果您只是想防止异常,则可以始终使用try/except。例如:

new_thread = Thread(target=music.play)
new_thread.daemon = True # Not always needed, read more about daemon property
new_thread.start()
with mic_manager as stream:
    while not stream.closed:
        try:
            audio_generator = stream.generator()
            requests = (speech.types.StreamingRecognizeRequest(
                audio_content=content)
                for content in audio_generator)

            responses = client.streaming_recognize(streaming_config,
                                                   requests)
            # Now, put the transcription responses to use.
            listen_print_loop(responses, stream, code)
        except BaseException as e:
            print("Exception occurred - {}".format(str(e)))