如何用引号("
s)附带JSON响应中的特定文本?我正在使用Python 3.6.0。如何用引号将json响应中的特定文本括起来?我在Windows 8中使用Python 3.6.0
我的脚本使用了Cloudsight图像识别API。这允许我上传图像并从Cloudsight获取该图像的描述。
现在,我想要做的是使用TTS命令行工具来说出来自Cloudsight的响应。我使用的TTS是https://github.com/brookhong/tts
我的问题是,如果TTS只能用引号("
s)括起来,那么它只能说出字符串。否则,它只会说出字符串中的最后一个单词。 这里是我试过到目前为止:
image_results = get_results_for_token(image_token, api_key) # This gets the JSON response from Cloudsight.
phrase = '"I think this shows "'
description =(image_results['name']) # This is for getting the string that I want from the JSON response.
combination = phrase + description
import subprocess
subprocess.call('tts.exe -f 10 -v 4 '+combination, shell=False) # Initialize TTS to speak out combination of phrase and description, which does not work as TTS only speaks out last word in description.
subprocess.call('tts.exe -f 10 -v 4 '+phrase, shell=False) # Try to speak out the phrase first, which works because it's enclosed by quotes.
subprocess.call('tts.exe -f 10 -v 4 '+description, shell=False) # Try to speak out description, which does not work. TTS only speaks out last word probably because the name string from the JSON response is not enclosed by quotes.
print(combination) # This works. The script is parsing the text correctly.
即使脚本正确地分析文本,语音合成只讲了描述中的最后一个字。即使我使用两个字符串的组合,以及单独的字符串,就像我在上面的代码中所做的那样。
什么可能是错的?
这是真棒! - 它马上解决了我的问题! :) – MichaelFuentes
这里是我的代码的工作版本: image_results = get_results_for_token(image_token,API_KEY) 短语= ' “我认为,这显示”' 描述=(image_results [ '名']) 组合=短语+描述 导入子程序 subprocess.call(['tts.exe',' - f','10',' - v','4',combination]) print(combination) 再次感谢Jean-François! :) – MichaelFuentes