如何用引号 ( "
s) 将 JSON 响应中的特定文本括起来?我正在使用 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.
即使脚本正确解析文本,TTS 也只会说出描述中的最后一个词。即使我使用两个字符串的组合和单独的字符串,就像我在上面的代码中所做的那样。
有什么问题?