亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

難以從 Flask 應用程序訪問 Google Text-to-Speech API

難以從 Flask 應用程序訪問 Google Text-to-Speech API

呼如林 2023-06-13 16:52:51
我在 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”來解決問題

查看完整回答
反對 回復 2023-06-13
  • 1 回答
  • 0 關注
  • 162 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號