我需要使用 python 和其他變數從 AWS EC2 運行 AWS CLI Polly 服務。問題在于 cmd 字串中的包含變數
import subprocess
row1 = 'My husband and I have done around 100 rooms and came to Barcelona as it has a reputation for top class rooms. We did Bajo Zero based on a recommendation from an escape room enthusiast in the UK and werent disappointed. It was a very well made immersive room with some clever puzzles. We chose hard mode and it was quite challenging as a pair but we did make it out in time. ,Escapem Elements Aire Escape Room'
cmd = 'aws polly synthesize-speech --output-format mp3 --engine neural --voice-id Kevin --text' row1 'speech1.mp3'
subprocess.call(cmd, shell=True)
此腳本命令是從 EC2 NOT local 執行的
uj5u.com熱心網友回復:
aws您可以使用boto3 庫直接呼叫 AWS ,而不是從 Python 呼叫程式。事實上,AWS CLI 是用 Python 撰寫的,也使用了這個庫!
然后您可以使用 boto3 呼叫 Polly。
例如:
import boto3
client = boto3.client('polly')
response = client.synthesize_speech(
Engine='neural',
LanguageCode='en-US',
OutputFormat='mp3',
Text='My husband and I have done around 100 rooms',
VoiceId='Kevin'
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/537791.html
上一篇:掛在膠爬蟲臺階上的臺階功能
