我在 Flask 應用程序中訪問 Google 的 texttospeech Python API 時遇到困難。該應用程序在安裝了 Debian 10、Nginx/Gunicorn 和 Python 3.7 的容器中運行。在下面的代碼中,客戶端連接成功,但 synthesize_speech 請求無限期掛起(沒有任何錯誤消息)。當我在沒有 Flask 的情況下從同一容器中的 Python 腳本運行相同的代碼時,語音合成請求成功。但是,我可以毫無問題地從我的 Flask 應用程序調用其他外部 API,例如 AWS 上的 API。是什么原因造成的,或者我該如何診斷問題?我嘗試切換到 texttospeech 庫的 1.0.1 版,但沒有成功。大概問題不是我的憑據,我相信我已經正確設置了憑據,否則連接請求將不會成功。from google.cloud import texttospeech# Connect (this is successful)client = texttospeech.TextToSpeechClient()input_text = texttospeech.SynthesisInput(text="God dag")voice_parameters = texttospeech.VoiceSelectionParams( language_code="sv-SE", name="sv-SE-Wavenet-A")audio_config = texttospeech.AudioConfig( audio_encoding=texttospeech.AudioEncoding.MP3)# Synthesize speech (this never completes)response = client.synthesize_speech( request={ "input": input_text, "voice": voice_parameters, "audio_config": audio_config })點凍結google-api-core==1.22.1google-auth==1.20.1google-cloud-texttospeech==2.2.0googleapis-common-protos==1.52.0grpcio==1.31.0...
1 回答

慕姐8265434
TA貢獻1813條經驗 獲得超2個贊
原來這個問題是由 gunicorn 的 gevent worker 類中的 monkey_patching 引起的。設法通過將 gunicorn 中的 worker_class 更改為“sync”來解決問題
添加回答
舉報
0/150
提交
取消