1 Star 0 Fork 7

XDW1993/JamTools

forked from borelist/JamTools 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
jamspeak.py 1.65 KB
一键复制 编辑 原始数据 按行查看 历史
#!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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/xdw1993/JamTools.git
git@gitee.com:xdw1993/JamTools.git
xdw1993
JamTools
JamTools
main

搜索帮助