kxxt / aspeak

A simple text-to-speech client for Azure TTS API.
MIT License
494 stars 57 forks source link

How can I use the variable for input parameter? #40

Closed bk111 closed 1 year ago

bk111 commented 1 year ago

print(type(names1["hot50_cntopic" + str(i) ][0:280])) #结果为 str

input1 = names1["hot50_cntopic" + str(i) ][0:280] input2 = "近日在全国多地,许多新冠感染者们已陆续转阴,回归到正常的生活和工作中。"

os.system('aspeak -t names1["hot50_cntopic" + str(i) ][0:280] -o "./1/{}{}{}_".format(year, month, day)+str(i)+".mp3" -l zh-CN') # 结果: -t names1["hot50_cntopic" + str(i) ][0:280] 格式不正常

os.system('aspeak -t input1 -v zh-CN-YunjianNeural -R YoungAdultMale -o "{}".mp3'.format(out1)) # 结果: -t input1 格式不正常

os.system('aspeak -t input2 -v zh-CN-YunjianNeural -R YoungAdultMale -o "{}".mp3'.format(out1)) # 结果: -t input2 格式不正常

os.system('aspeak -t """近日在全国多地,许多新冠感染者们已陆续转阴,回归到正常的生活和工作中。""" -v zh-CN-YunjianNeural -R YoungAdultMale -o "{}".mp3'.format(out1)) #这个是正常的

-t 之后的输入参数 怎么才能换成变量呢?

kxxt commented 1 year ago

你既然已经在用 Python 了,为什么不直接调 API 呢?😂

文档:https://github.com/kxxt/aspeak/blob/main/DEVELOP.md

如果要用 CLI 的话,也没必要直接拼接命令啊.... 拼接命令要先转义字符串。直接从 stdin 读入多好

from subprocess import run
run(executable='aspeak', args=['-t', '-l', 'zh-CN', '-o', 'result.wav'], input='放你想要的字符串', encoding='utf-8')