ChatGPT写的语音播报程序

程序test.py代码如下

import os
import platform

def speak_text(text):
    if platform.system() == "Windows":
        os.system("powershell -Command Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('" + text + "')")
    else:
        os.system("say " + text)

with open("text.txt", "r", encoding="utf-8") as file:
    text = file.read()

speak_text(text)

文档内容自己随意,我的如下text.txt放到以上程序test.py同一文件夹:

玉桂狗的耳朵很大是因为这是该品种的特征之一。玉桂狗是一种受人喜爱的狗品种,具有大耳朵、长毛和聪明的特征。这些特征对于这种狗品种来说是遗传的,它们是通过长期的培育和选择所得到的。不同品种的狗有不同的特征,而这些特征是由专业的饲养员通过严格的训练和选择来改变的。

运行一下,挺好的。

猜你喜欢

转载自blog.csdn.net/weixin_44345862/article/details/128965948
今日推荐