import re
import pyttsx3
def voice_list():
# 创建对象
engine = pyttsx3.init()
# 获取当前语音声音的详细信息,并试听语音
voices = engine.getProperty('voices')
# 從語音信息是提取機器人姓名並試音
v = 0 # 语音索引号
list_v = []
for voice in voices:
# print(f'语音声音详细信息:{voice}')
# print(type(voice))
# str1 = str(voice)[82:100]
str1 = str(voice)[100:140].lstrip() # 將多行語音信息提取部分並去掉左空格
# print(v, '号', str1)
# print(type(str1))
pattern = r" (.*?) " # 匹配規則:匹配兩者之间的内容
str2 = re.search(pattern, str1).group(1)
str3 = str(voice)[50:100].lstrip()
if 'CN' in str3:
str3 = '普通话'
str4 = '我会说'
if 'HK' in str3:
str3 = '粤语'
str4 = '我会说'
if 'TW' in str3:
str3 = '国语'
str4 = '我会说'
if 'EN' in str3:
str3 = 'English'
str4 = 'I am the ',v,'voice robot, and my name is ',str2,'I can speak'
txt_v = str(v)+'号'+str2+'('+str3+')'
# print(txt_v)
v = v + 1
list_v.append(txt_v)
return list_v
def audition():
# 创建对象
engine = pyttsx3.init()
# 获取当前语音速率
rate = engine.getProperty('rate')
# print(f'语音速率:{rate}')
# 设置新的语音速率
engine.setProperty('rate', 150)
# 获取当前语音音量
volume = engine.getProperty('volume')
# print(f'语音音量:{volume}')
# 设置新的语音音量,音量最小为 0,最大为 1
engine.setProperty('volume', 1.0)
# 获取当前语音声音的详细信息,并试听语音
voices = engine.getProperty('voices')
list_v = voice_list()
for v in range(len(list_v)):
engine.setProperty('voice', voices[v].id)
engine.say("大家好,我是语音机器人%s" % (list_v[v]))
print("大家好,我是语音机器人%s" % (list_v[v]))
engine.runAndWait()
audition() # 试听语音
上述代码能试听你的电脑系统安装的语音种类。
考试指令系统下载链接:https://pan.baidu.com/s/11x9fS1gUEPCd6w15KHCxSw?pwd=zvw3
提取码:zvw3
极域电子教室座位表程序下载链接:https://pan.baidu.com/s/1dvW5q9G53prkUDVcO6uffA?pwd=w3jp
照片插入电子表格程序链接:https://pan.baidu.com/s/1dvW5q9G53prkUDVcO6uffA?pwd=w3jp
提取码:w3jp