Python 神经声音不';方济各医院
我正在为端点使用API: 我正在尝试实现本网站提供的教程: 但是我不能让它工作。当我得到一个列表时,Voices不显示pt BR FranciscaNeural,但在文档中它表示该语音可用Python 神经声音不';方济各医院,python,azure,text-to-speech,Python,Azure,Text To Speech,我正在为端点使用API: 我正在尝试实现本网站提供的教程: 但是我不能让它工作。当我得到一个列表时,Voices不显示pt BR FranciscaNeural,但在文档中它表示该语音可用 import requests import time from xml.etree import ElementTree try: input = input except NameError: pass class TextToSpeech(object): def __ini
import requests
import time
from xml.etree import ElementTree
try:
input = input
except NameError:
pass
class TextToSpeech(object):
def __init__(self, subscription_key):
self.subscription_key = subscription_key
self.tts = input("What would you like to convert to speech: ")
self.timestr = time.strftime("%Y%m%d-%H%M")
self.access_token = None
def get_token(self):
fetch_token_url = "https://brazilsouth.api.cognitive.microsoft.com/sts/v1.0/issueToken"
headers = {
'Ocp-Apim-Subscription-Key': self.subscription_key
}
response = requests.post(fetch_token_url, headers=headers)
self.access_token = str(response.text)
def save_audio(self):
base_url = 'https://brazilsouth.tts.speech.microsoft.com/'
path = 'cognitiveservices/v1'
constructed_url = base_url + path
headers = {
'Authorization': 'Bearer ' + self.access_token,
'Content-Type': 'application/ssml+xml',
'X-Microsoft-OutputFormat': 'riff-24khz-16bit-mono-pcm',
'User-Agent': 'YOUR_RESOURCE_NAME'
}
xml_body = ElementTree.Element('speak', version='1.0')
xml_body.set('{http://www.w3.org/XML/1998/namespace}lang', 'pt-br')
voice = ElementTree.SubElement(xml_body, 'voice')
voice.set('{http://www.w3.org/XML/1998/namespace}lang', 'pt-BR')
voice.set(
'name', 'Microsoft Server Speech Text to Speech Voice (pt-BR, FranciscaNeural)')
voice.text = self.tts
body = ElementTree.tostring(xml_body)
response = requests.post(constructed_url, headers=headers, data=body)
if response.status_code == 200:
with open('sample-' + self.timestr + '.wav', 'wb') as audio:
audio.write(response.content)
print("\nStatus code: " + str(response.status_code) +
"\nYour TTS is ready for playback.\n")
else:
print("\nStatus code: " + str(response.status_code) +
"\nSomething went wrong. Check your subscription key and headers.\n")
if __name__ == "__main__":
subscription_key = "put-here-a-keycode"
app = TextToSpeech(subscription_key)
app.get_token()
app.save_audio()
请参考此线程:
根据线程,有一个已知问题正在积极解决,并且在修复之前,pt BR FranciscaNeural已被故意删除。我解决了问题,我更改了服务器的位置,因为我发现我使用的不符合神经语言
我设法用另一台服务器使用了方济各的声音:
fetch_token_url="https://eastus.api.cognitive.microsoft.com/sts/v1.0/issueToken"
它工作得很好欢迎使用SO!请向我们展示您迄今为止所做的工作,您可能希望阅读此文以帮助澄清您的问题:我在那里输入了一个代码。我使用另一台服务器使用了方济各的声音:
featch_token\u url=”https://eastus.api.cognitive.microsoft.com/sts/v1.0/issueToken“
。。。如果你所在地区不存在神经语言,我建议你使用另一种。仅支持某些位置此处是支持列表: