当前位置:   article > 正文

python编译Edge-tts: Edge tts Player_pythton edge-tts

pythton edge-tts

Edge-TTS是Python库,通过微软Azure Cognitive Services转化文本为自然语音,Edge-TTS支持40多种语言和300种声音,提供优质的语音输出,这给学习外语的学生和老师很大的福利。

下面,尝试着用python来编写一个简单的TTS转MP3。Edge TTS

  1. from tkinter import *
  2. from tkinter import ttk
  3. from tkinter.filedialog import *
  4. from tkinter.messagebox import *
  5. from tkinter import scrolledtext
  6. import os
  7. import edge_tts
  8. import asyncio
  9. import win32clipboard as w
  10. import win32con
  11. top = Tk()
  12. top.title("浩读系列 MS-Edge-TTS V20240512 Wechat 15308968361")
  13. top.geometry("1024x768")
  14. combo = ttk.Combobox(width=30, height=40,values=["af-ZA-AdriNeural", "af-ZA-WillemNeural", "am-ET-AmehaNeural", "am-ET-MekdesNeural", "ar-AE-FatimaNeural", "ar-AE-HamdanNeural", "ar-BH-AliNeural", "ar-BH-LailaNeural", "ar-DZ-AminaNeural", "ar-DZ-IsmaelNeural", "ar-EG-SalmaNeural", "ar-EG-ShakirNeural", "ar-IQ-BasselNeural", "ar-IQ-RanaNeural", "ar-JO-SanaNeural", "ar-JO-TaimNeural", "ar-KW-FahedNeural", "ar-KW-NouraNeural", "ar-LB-LaylaNeural", "ar-LB-RamiNeural", "ar-LY-ImanNeural", "ar-LY-OmarNeural", "ar-MA-JamalNeural", "ar-MA-MounaNeural", "ar-OM-AbdullahNeural", "ar-OM-AyshaNeural", "ar-QA-AmalNeural", "ar-QA-MoazNeural", "ar-SA-HamedNeural", "ar-SA-ZariyahNeural", "ar-SY-AmanyNeural", "ar-SY-LaithNeural", "ar-TN-HediNeural", "ar-TN-ReemNeural", "ar-YE-MaryamNeural", "ar-YE-SalehNeural", "az-AZ-BabekNeural", "az-AZ-BanuNeural", "bg-BG-BorislavNeural", "bg-BG-KalinaNeural", "bn-BD-NabanitaNeural", "bn-BD-PradeepNeural", "bn-IN-BashkarNeural", "bn-IN-TanishaaNeural", "bs-BA-GoranNeural", "bs-BA-VesnaNeural", "ca-ES-EnricNeural", "ca-ES-JoanaNeural", "cs-CZ-AntoninNeural", "cs-CZ-VlastaNeural", "cy-GB-AledNeural", "cy-GB-NiaNeural", "da-DK-ChristelNeural", "da-DK-JeppeNeural", "de-AT-IngridNeural", "de-AT-JonasNeural", "de-CH-JanNeural", "de-CH-LeniNeural", "de-DE-AmalaNeural", "de-DE-ConradNeural", "de-DE-FlorianMultilingualNeural", "de-DE-KatjaNeural", "de-DE-KillianNeural", "de-DE-SeraphinaMultilingualNeural", "el-GR-AthinaNeural", "el-GR-NestorasNeural", "en-AU-NatashaNeural", "en-AU-WilliamNeural", "en-CA-ClaraNeural", "en-CA-LiamNeural", "en-GB-LibbyNeural", "en-GB-MaisieNeural", "en-GB-RyanNeural", "en-GB-SoniaNeural", "en-GB-ThomasNeural", "en-HK-SamNeural", "en-HK-YanNeural", "en-IE-ConnorNeural", "en-IE-EmilyNeural", "en-IN-NeerjaExpressiveNeural", "en-IN-NeerjaNeural", "en-IN-PrabhatNeural", "en-KE-AsiliaNeural", "en-KE-ChilembaNeural", "en-NG-AbeoNeural", "en-NG-EzinneNeural", "en-NZ-MitchellNeural", "en-NZ-MollyNeural", "en-PH-JamesNeural", "en-PH-RosaNeural", "en-SG-LunaNeural", "en-SG-WayneNeural", "en-TZ-ElimuNeural", "en-TZ-ImaniNeural", "en-US-AnaNeural", "en-US-AndrewMultilingualNeural", "en-US-AndrewNeural", "en-US-AriaNeural", "en-US-AvaMultilingualNeural", "en-US-AvaNeural", "en-US-BrianMultilingualNeural", "en-US-BrianNeural", "en-US-ChristopherNeural", "en-US-EmmaMultilingualNeural", "en-US-EmmaNeural", "en-US-EricNeural", "en-US-GuyNeural", "en-US-JennyNeural", "en-US-MichelleNeural", "en-US-RogerNeural", "en-US-SteffanNeural", "en-ZA-LeahNeural", "en-ZA-LukeNeural", "es-AR-ElenaNeural", "es-AR-TomasNeural", "es-BO-MarceloNeural", "es-BO-SofiaNeural", "es-CL-CatalinaNeural", "es-CL-LorenzoNeural", "es-CO-GonzaloNeural", "es-CO-SalomeNeural", "es-CR-JuanNeural", "es-CR-MariaNeural", "es-CU-BelkysNeural", "es-CU-ManuelNeural", "es-DO-EmilioNeural", "es-DO-RamonaNeural", "es-EC-AndreaNeural", "es-EC-LuisNeural", "es-ES-AlvaroNeural", "es-ES-ElviraNeural", "es-ES-XimenaNeural", "es-GQ-JavierNeural", "es-GQ-TeresaNeural", "es-GT-AndresNeural", "es-GT-MartaNeural", "es-HN-CarlosNeural", "es-HN-KarlaNeural", "es-MX-DaliaNeural", "es-MX-JorgeNeural", "es-NI-FedericoNeural", "es-NI-YolandaNeural", "es-PA-MargaritaNeural", "es-PA-RobertoNeural", "es-PE-AlexNeural", "es-PE-CamilaNeural", "es-PR-KarinaNeural", "es-PR-VictorNeural", "es-PY-MarioNeural", "es-PY-TaniaNeural", "es-SV-LorenaNeural", "es-SV-RodrigoNeural", "es-US-AlonsoNeural", "es-US-PalomaNeural", "es-UY-MateoNeural", "es-UY-ValentinaNeural", "es-VE-PaolaNeural", "es-VE-SebastianNeural", "et-EE-AnuNeural", "et-EE-KertNeural", "fa-IR-DilaraNeural", "fa-IR-FaridNeural", "fi-FI-HarriNeural", "fi-FI-NooraNeural", "fil-PH-AngeloNeural", "fil-PH-BlessicaNeural", "fr-BE-CharlineNeural", "fr-BE-GerardNeural", "fr-CA-AntoineNeural", "fr-CA-JeanNeural", "fr-CA-SylvieNeural", "fr-CA-ThierryNeural", "fr-CH-ArianeNeural", "fr-CH-FabriceNeural", "fr-FR-DeniseNeural", "fr-FR-EloiseNeural", "fr-FR-HenriNeural", "fr-FR-RemyMultilingualNeural", "fr-FR-VivienneMultilingualNeural", "ga-IE-ColmNeural", "ga-IE-OrlaNeural", "gl-ES-RoiNeural", "gl-ES-SabelaNeural", "gu-IN-DhwaniNeural", "gu-IN-NiranjanNeural", "he-IL-AvriNeural", "he-IL-HilaNeural", "hi-IN-MadhurNeural", "hi-IN-SwaraNeural", "hr-HR-GabrijelaNeural", "hr-HR-SreckoNeural", "hu-HU-NoemiNeural", "hu-HU-TamasNeural", "id-ID-ArdiNeural", "id-ID-GadisNeural", "is-IS-GudrunNeural", "is-IS-GunnarNeural", "it-IT-DiegoNeural", "it-IT-ElsaNeural", "it-IT-GiuseppeNeural", "it-IT-IsabellaNeural", "ja-JP-KeitaNeural", "ja-JP-NanamiNeural", "jv-ID-DimasNeural", "jv-ID-SitiNeural", "ka-GE-EkaNeural", "ka-GE-GiorgiNeural", "kk-KZ-AigulNeural", "kk-KZ-DauletNeural", "km-KH-PisethNeural", "km-KH-SreymomNeural", "kn-IN-GaganNeural", "kn-IN-SapnaNeural", "ko-KR-HyunsuNeural", "ko-KR-InJoonNeural", "ko-KR-SunHiNeural", "lo-LA-ChanthavongNeural", "lo-LA-KeomanyNeural", "lt-LT-LeonasNeural", "lt-LT-OnaNeural", "lv-LV-EveritaNeural", "lv-LV-NilsNeural", "mk-MK-AleksandarNeural", "mk-MK-MarijaNeural", "ml-IN-MidhunNeural", "ml-IN-SobhanaNeural", "mn-MN-BataaNeural", "mn-MN-YesuiNeural", "mr-IN-AarohiNeural", "mr-IN-ManoharNeural", "ms-MY-OsmanNeural", "ms-MY-YasminNeural", "mt-MT-GraceNeural", "mt-MT-JosephNeural", "my-MM-NilarNeural", "my-MM-ThihaNeural", "nb-NO-FinnNeural", "nb-NO-PernilleNeural", "ne-NP-HemkalaNeural", "ne-NP-SagarNeural", "nl-BE-ArnaudNeural", "nl-BE-DenaNeural", "nl-NL-ColetteNeural", "nl-NL-FennaNeural", "nl-NL-MaartenNeural", "pl-PL-MarekNeural", "pl-PL-ZofiaNeural", "ps-AF-GulNawazNeural", "ps-AF-LatifaNeural", "pt-BR-AntonioNeural", "pt-BR-FranciscaNeural", "pt-BR-ThalitaNeural", "pt-PT-DuarteNeural", "pt-PT-RaquelNeural", "ro-RO-AlinaNeural", "ro-RO-EmilNeural", "ru-RU-DmitryNeural", "ru-RU-SvetlanaNeural", "si-LK-SameeraNeural", "si-LK-ThiliniNeural", "sk-SK-LukasNeural""sk-SK-ViktoriaNeural", "sl-SI-PetraNeural", "sl-SI-RokNeural", "so-SO-MuuseNeural", "so-SO-UbaxNeural", "sq-AL-AnilaNeural", "sq-AL-IlirNeural", "sr-RS-NicholasNeural", "sr-RS-SophieNeural", "su-ID-JajangNeural", "su-ID-TutiNeural", "sv-SE-MattiasNeural", "sv-SE-SofieNeural", "sw-KE-RafikiNeural", "sw-KE-ZuriNeural", "sw-TZ-DaudiNeural", "sw-TZ-RehemaNeural", "ta-IN-PallaviNeural", "ta-IN-ValluvarNeural", "ta-LK-KumarNeural", "ta-LK-SaranyaNeural", "ta-MY-KaniNeural", "ta-MY-SuryaNeural", "ta-SG-AnbuNeural", "ta-SG-VenbaNeural", "te-IN-MohanNeural", "te-IN-ShrutiNeural", "th-TH-NiwatNeural", "th-TH-PremwadeeNeural", "tr-TR-AhmetNeural", "tr-TR-EmelNeural", "uk-UA-OstapNeural", "uk-UA-PolinaNeural", "ur-IN-GulNeural", "ur-IN-SalmanNeural", "ur-PK-AsadNeural", "ur-PK-UzmaNeural", "uz-UZ-MadinaNeural", "uz-UZ-SardorNeural"
  15. , "vi-VN-HoaiMyNeural", "vi-VN-NamMinhNeural", "zh-CN-XiaoxiaoNeural", "zh-CN-XiaoyiNeural", "zh-CN-YunxiNeural", "zh-CN-YunxiaNeural", "zh-CN-YunyangNeural", "zh-CN-liaoning-XiaobeiNeural", "zh-CN-shaanxi-XiaoniNeural", "zh-HK-HiuGaaiNeural", "zh-HK-HiuMaanNeural", "zh-HK-WanLungNeural", "zh-TW-HsiaoChenNeural", "zh-TW-HsiaoYuNeural", "zh-TW-YunJheNeural", "zu-ZA-ThandoNeural", "zu-ZA-ThembaNeural"])
  16. combo.configure(font=("Arial","16"))
  17. combo.pack()
  18. # Set the default value
  19. combo.current(70)
  20. # Function to get the selected value
  21. def get_selected_value():
  22. selected_value = combo.get()
  23. print("Selected value:", selected_value)
  24. VOICE =selected_value
  25. gt= textPad.get(1.0, END)
  26. TEXT=gt
  27. if __name__ == "__main__":
  28. loop = asyncio.new_event_loop()
  29. asyncio.set_event_loop(loop)
  30. try:
  31. loop.run_until_complete(amain(TEXT, VOICE))
  32. finally:
  33. loop.close()
  34. OUTPUT_FILE = "YourMp3.mp3"
  35. WEBVTT_FILE = "YourMp3.vtt"
  36. def main(TEXT, VOICE) -> None:
  37. """Main function to process audio and metadata synchronously."""
  38. communicate = edge_tts.Communicate(TEXT, VOICE)
  39. submaker = edge_tts.SubMaker()
  40. with open(OUTPUT_FILE, "wb") as file:
  41. for chunk in communicate.stream_sync():
  42. if chunk["type"] == "audio":
  43. file.write(chunk["data"])
  44. elif chunk["type"] == "WordBoundary":
  45. submaker.create_sub((chunk["offset"], chunk["duration"]), chunk["text"])
  46. with open(WEBVTT_FILE, "w", encoding="utf-8") as file:
  47. file.write(submaker.generate_subs())
  48. async def amain(TEXT, VOICE) -> None:
  49. """ "
  50. Async main function to call sync main function
  51. This demonstrates that this works even when called from an async function.
  52. """
  53. main(TEXT, VOICE)
  54. def cut():
  55. global textPad
  56. textPad.event_generate("<<Cut>>")
  57. def copy():
  58. global textPad
  59. textPad.event_generate("<<Copy>>")
  60. def paste():
  61. global textPad
  62. textPad.event_generate("<<Paste>>")
  63. def undo():
  64. global textPad
  65. textPad.event_generate("<<Undo>>")
  66. def redo():
  67. global textPad
  68. textPad.event_generate("<<Redo>>")
  69. def select_all():
  70. global textPad
  71. textPad.tag_add("sel", "1.0", "end")
  72. def mypopup(event):
  73. global editmenu
  74. editmenu.tk_popup(event.x_root, event.y_root)
  75. def refresh():
  76. global top, filename
  77. if filename:
  78. top.title(os.path.basename(filename))
  79. else:
  80. top.title("浩读系列 MS-Edge-TTS V20240512 Wechat 15308968361")
  81. menubar = Menu(top)
  82. filemenu = Menu(top)
  83. top['menu'] = menubar
  84. menubar.add_cascade(label="转成MP3", menu=aboutmenu)
  85. aboutmenu = Menu(top)
  86. aboutmenu.add_command(label="To MP3 by selected voice of Listbox", command=get_selected_value)
  87. shortcutbar = Frame(top, height=25, bg='Silver')
  88. shortcutbar.pack(expand=NO, fill=X)
  89. textPad=Text(top, undo=True)
  90. scroll=Scrollbar(textPad,width=20)
  91. textPad.config(yscrollcommand=scroll.set,wrap="word",borderwidt=20,font=25)
  92. scroll.config(command=textPad.yview)
  93. textPad.pack(expand=YES, fill=BOTH)
  94. textPad.bind("<Control-N>", new_file)
  95. textPad.bind("<Control-n>", new_file)
  96. textPad.bind("<Control-O>", open_file)
  97. textPad.bind("<Control-o>", open_file)
  98. textPad.bind("<Control-S>", save)
  99. textPad.bind("<Control-s>", save)
  100. textPad.bind("<Control-D>", delete)
  101. textPad.bind("<Control-d>", delete)
  102. textPad.bind("<Control-R>", rename_file)
  103. textPad.bind("<Control-r>", rename_file)
  104. textPad.bind("<Control-A>", select_all)
  105. textPad.bind("<Control-a>", select_all)
  106. textPad.bind("<Button-3>", mypopup)
  107. top.mainloop()

下载完成版地址: http://readall.ysepan.com/

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/神奇cpp/article/detail/777531
推荐阅读
相关标签
  

闽ICP备14008679号