代码拉取完成,页面将自动刷新
#!usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2021/9/2 22:52
# @Author : Fandes
# @FileName: jamspeak.py
# @Software: PyCharm
import os
import random
import sys
import time
import requests
import pyttsx3
if sys.platform == "win32":
import pyttsx3.drivers
import pyttsx3.drivers.sapi5
try:
speaker_engine = pyttsx3.init()
except:
e = sys.exc_info()
if "libespeak.so" in e[1].args[0]:
try:
os.system("sudo apt-get install espeak -y")
except Exception as ex:
print("linux下驱动未安装,请尝试使用`sudo apt-get install espeak`命令进行安装",ex)
print(e, __file__)
speaker_engine = None
class Speaker():
def speak(self, text="none", lan="en"):
try:
self.stop()
speaker_engine.say(text)
# speaker_engine.startLoop(False)
speaker_engine.runAndWait()
except:
e = sys.exc_info()
if "libespeak.so" in e[1].args[0]:
try:
os.system("sudo apt-get install espeak -y")
except Exception as ex:
print("linux下驱动未安装,请尝试使用`sudo apt-get install espeak`命令进行安装",ex)
print(e, __file__)
def stop(self):
if speaker_engine is not None and speaker_engine.isBusy():
speaker_engine.stop()
def is_alphabet(self, uchar):
"""判断一个unicode是否是英文字母"""
if (u'\u0041' <= uchar <= u'\u005a') or (u'\u0061' <= uchar <= u'\u007a'):
return True
else:
return False
if __name__ == '__main__':
s = Speaker()
s.speak()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。