2310241108

ubuntu

festival

apt install festival
echo “hello”|festival –tts

只适用英文,内存形式

https://qastack.cn/ubuntu/501910/how-to-text-to-speech-output-using-command-line 如何使用命令行进行文本转语音输出?

mandarin-tts

mandarin-tts项目好用

windows

sapi

可用于中文tts,文件形式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from comtypes.client import CreateObject
try:
from comtypes.gen import SpeechLib
except ImportError:
engine=CreateObject('SAPI.SpVoice')
stream=CreateObject('SAPI.SpFileStream')
from comtypes.gen import SpeechLib

engine=CreateObject('SAPI.SpVoice')
stream=CreateObject('SAPI.SpFileStream')

for le in l:
stream.Open(f'audios/{le}.wav',SpeechLib.SSFMCreateForWrite)
engine.AudioOutputStream=stream
engine.speak(le)
stream.close()

l是一个汉字序列的列表

https://blog.csdn.net/m0_46521785/article/details/108063360 python进行语音播报并保存音频_python speaker.speak_笼中小夜莺的博客-CSDN博客

https://blog.csdn.net/jacke121/article/details/84324876 cannot import name ‘SpeechLib’_AI视觉网奇的博客-CSDN博客

speech库

pip install speech # (在此之前,需要有pywin32库依赖),本质上调用的还是SAPI

1
2
3
4
import speech

speech.say('hello world')
speech.say('你好,世界')

另外subl C:\Users\tellw\AppData\Local\Programs\Python\Python310\lib\site-packages\speech.py,
修改一:第157行,print prompt改为print(prompt)。
修改二:第59行,thread改为_thread。
修改三:最后一行的thread应该改为_threading。

能够听到语音。

另外改发音人,打开控制面板的语音识别选项,选择文本到语音转换,更改发音人选项。

speech库还能做语音识别,words=speech.input(),words就是识别结果,调用的是windows服务api,所以可能效果不好,可以进入控制面板的语音识别选项里训练识别模型。

以上内容参考自https://zhuanlan.zhihu.com/p/391936240 Python基于Windows的语音合成模块——speech - 知乎 (zhihu.com)

双系统都可用

VITS-paimon

https://github.com/JOETtheIV/VITS-Paimon/releases 下载模型G_1434000.pth

https://github.com/JOETtheIV/VITS-Paimon git clone VITS-Paimon,把模型拷贝到本目录中

https://espeak.sourceforge.net/download.html espeak: Downloads (sourceforge.net)下载并安装espeak

进入VITS-Paimon目录,cd monotonic_align,python setup.py build_ext –inplace(两个短横,页面渲染的问题,显示一个短横,一个短横会引起错误),命令输出的最后一些内容是正在生成代码,已完成代码的生成。如果没有说完成代码的生成,只是列出了生成so文件的gcc命令,会发现monotonic_align对应的位置并没有那个文件,需要你手动创建必要的目录和执行这些命令。毕竟python在淘汰旧有的技术,这条命令所进行的工作比较老,新版本的库不完全支持它了。以后或许有新的方法。这样在导入monotonic_align这个包时,能执行from monotonic_align.core import xxxx语句。

test.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import utils
from models import SynthesizerTrn
from text import text_to_sequence
import commons
import torch
from text.symbols import symbols

def get_text(text,hps):
text_norm=text_to_sequence(text,hps.data.text_cleaners)
if hps.data.add_blank:
text_norm=commons.intersperse(text_norm,0)
text_norm=torch.LongTensor(text_norm)
return text_norm

hps=utils.get_hparams_from_file('configs/biaobei_base.json')

net_g=SynthesizerTrn(len(symbols),hps.data.filter_length//2+1,hps.train.segment_size//hps.data.hop_length,**hps.model).cuda()
_=net_g.eval()

_=utils.load_checkpoint('G_1434000.pth',net_g,None)
import soundfile as sf
text='你好,给我爬啊'
length_scale=1.0
filename='text'
audio_path=f'{filename}.wav'
stn_tst=get_text(text,hps)
with torch.no_grad():
x_tst=stn_tst.cuda().unsqueeze(0)
x_tst_lengths=torch.LongTensor([stn_tst.size(0)]).cuda()
audio=net_g.infer(x_tst,x_tst_lengths,noise_scale=.667,noise_scale_w=0.8,length_scale=length_scale)[0][0,0].data.cpu().float().numpy()
sf.write(audio_path,audio,samplerate=hps.data.sampling_rate)

python test.py,test.wav就是生成的语音文件

vits-simple-api

详见/2023/10/10/入门vits-simple-api项目/

https://colab.research.google.com/drive/1HDV84t3N-yUEBXN8dDIDSv6CzEJykCLw#scrollTo=oiPvCIJ_MHot

https://blog.csdn.net/potato_uncle/article/details/113016432 Espeak最详细安装过程!_是土豆大叔啊!的博客-CSDN博客

用机器tts快速、简单,直接了然,知道答案的题目,题目和答案同时出出来了,批量的题,由不同的音源出出来不同角度的题目