import requests
r = requests.get(
"https://speech.platform.bing.com/consumer/speech/synthesize/readaloud/voices/list?trustedclienttoken=6A5AA1D4EAFF4E9FB37E23D68491D6F4"
)
languages = [(lang["Name"], lang["ShortName"].replace("-", "_")) for lang in r.json()]
def gen(languages):
enum_variants = [
" #[allow(non_camel_case_types)]\n " + short_name
for _, short_name in languages
]
cases = [
f""" Voice::{short_name} => {{"{name}"}}"""
for name, short_name in languages
]
enum = ",\n".join(enum_variants)
match = "\n".join(cases)
templ = f"""// This file is generated by tools/voices.py
// Do not edit manually
#[repr(C)]
pub enum Voice {{
{enum}
}}
impl From<Voice> for &str {{
fn from(voice: Voice) -> Self {{
match voice {{
{match}
}}
}}
}}
"""
with open("src/voices.rs", "w") as f:
f.write(templ)
if __name__ == "__main__":
gen(languages)