text to sound 文本转语音

import pyttsx3
# import requests
# from bs4 import BeautifulSoup
# #contents = "null "
# def content(url):
#     res = requests.get(url)
#     soup = BeautifulSoup(res.text,'html.parser')
#     #soup = BeautifulSoup(res.text,'lxml')
#     articles = []
#     for i in range(len(soup.select('p'))):
#         article = soup.select('p')[i].getText().strip()
#         articles.append(article)
#         contents = " ".join(articles)
#         return contents
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)

def speak(audio):
    engine.say(audio)
    engine.runAndWait()
    
# url = str(input("Paste article url\n"))
# contents=content(url)
contents = ''' 11点聚会完,赵敏狂犬疫苗打第五针,带上粽子
……上高速,12:10分到家了,吃的捞面,,睡醒吃两块西瓜,
天要下雨了,4:30晚会走,6点到家里了,今天没课,
营销选修课考试成绩需要处理。  
'''
print(contents)      ## In case you want to see the content
speak(contents)
#engine.save_to_file
#engine.runAndWait()  ## In case if you want to save the article as a audio file