python 文本转语音
https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/quickstart/python/text-to-speech/
https://github.com/microsoft/cognitive-services-speech-sdk-js
写的垃圾程序,能用
from lxml import html
import requests
import os
import asyncio
import edge_tts
voice = 'zh-CN-YunxiNeural'
mp3_folder = 'mp3'
async def text_to_speech(text, filename):
tts = edge_tts.Communicate(text=text, voice=voice)
await tts.save(os.path.join(mp3_folder, filename + '.mp3'))
async def main_async():
url = 'http://www.bookbens.com/read/115085/63721689.html'
filename = url.split('/')[-1].split('.')[0]
print(filename)
if not os.path.exists(mp3_folder):
os.mkdir(mp3_folder)
page = requests.get(url)
tree = html.fromstring(page.content)
div_element = tree.xpath('/html/body/article/div[4]/div')[0]
# print(div_element.text_content())
text_content = div_element.text_content()
with open('book1/output.txt', 'w') as f:
f.write(text_content)
await text_to_speech(text_content, filename)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
task = loop.create_task(main_async())
loop.run_until_complete(task)