最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Azure Python Speech Sdk get mstts:express-as styles from API - Stack Overflow

programmeradmin0浏览0评论

I have a Python Kivy App where you can use different TTS APIs. I use the basic SSML-Tags but I want to add the Microsoft exclusive styles of the mstts:express-as attribute. Is there any way to get the available styles for each voice dynamically from the API without having to hardcode it for 50 voices?

I have a Python Kivy App where you can use different TTS APIs. I use the basic SSML-Tags but I want to add the Microsoft exclusive styles of the mstts:express-as attribute. Is there any way to get the available styles for each voice dynamically from the API without having to hardcode it for 50 voices?

Share Improve this question asked Mar 13 at 10:25 JoeJoe 253 bronze badges 2
  • 1 Use the voices/list API to get available styles dynamically from the StyleList field. – Dasari Kamali Commented Mar 13 at 10:39
  • I retrieved the styles list, which is available for 50 voices. – Dasari Kamali Commented Mar 13 at 11:11
Add a comment  | 

1 Answer 1

Reset to default 1

I tried the below code to get the available styles for each voice from the Azure Text-to-Speech API.

I modified the line below in the code to retrieve the available styles for 50 voices without any issues.

for voice in voices[:50]:

app.py :

import requests

speech_key = "<SppechKey>"
region = "<SpeechRegion>"
endpoint = f"https://{region}.tts.speech.microsoft/cognitiveservices/voices/list"

headers = {
    "Ocp-Apim-Subscription-Key": speech_key
}

response = requests.get(endpoint, headers=headers)
voices = response.json()
for voice in voices:
    full_name = voice["Name"]
    short_name = voice.get("ShortName", "N/A")
    styles = voice.get("StyleList", []) 
    print(f"Full Name: {full_name}, Short Name: {short_name}")
    if styles:
        print(f"Voice: {short_name}, Styles: {', '.join(styles)}")
    else:
        print(f"Voice: {short_name}, Styles: None")

Output :

I successfully retrieved the list of styles available for 50 Text-to-Speech voices.

发布评论

评论列表(0)

  1. 暂无评论