我在 Flask 應(yīng)用程序中訪問(wèn) Google 的 texttospeech Python API 時(shí)遇到困難。該應(yīng)用程序在安裝了 Debian 10、Nginx/Gunicorn 和 Python 3.7 的容器中運(yùn)行。在下面的代碼中,客戶端連接成功,但 synthesize_speech 請(qǐng)求無(wú)限期掛起(沒有任何錯(cuò)誤消息)。當(dāng)我在沒有 Flask 的情況下從同一容器中的 Python 腳本運(yùn)行相同的代碼時(shí),語(yǔ)音合成請(qǐng)求成功。但是,我可以毫無(wú)問(wèn)題地從我的 Flask 應(yīng)用程序調(diào)用其他外部 API,例如 AWS 上的 API。是什么原因造成的,或者我該如何診斷問(wèn)題?我嘗試切換到 texttospeech 庫(kù)的 1.0.1 版,但沒有成功。大概問(wèn)題不是我的憑據(jù),我相信我已經(jīng)正確設(shè)置了憑據(jù),否則連接請(qǐng)求將不會(huì)成功。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 })點(diǎn)凍結(jié)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貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊
原來(lái)這個(gè)問(wèn)題是由 gunicorn 的 gevent worker 類中的 monkey_patching 引起的。設(shè)法通過(guò)將 gunicorn 中的 worker_class 更改為“sync”來(lái)解決問(wèn)題
添加回答
舉報(bào)
0/150
提交
取消
