Added Python script from video on GPT4ALL and Coqui TTS

https://youtu.be/FBXA-DPyNrA
This commit is contained in:
Thorsten Müller 2023-04-26 21:40:40 +02:00 committed by GitHub
parent f13bcaf63e
commit 28831d8642
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,27 @@
from pygpt4all.models.gpt4all_j import GPT4All_J
from TTS.api import TTS
import wave,sys,pyaudio
def new_text_callback(text):
print(text, end="")
model = GPT4All_J('./ggml-gpt4all-j-v1.2-jazzy.bin')
outText = model.generate("Once upon a time, ", n_predict=55, new_text_callback=new_text_callback)
print(outText)
tts = TTS(model_name="tts_models/en/ljspeech/vits--neon")
tts.tts_to_file(text=outText)
wf = wave.open('output.wav')
p = pyaudio.PyAudio()
chunk = 1024
stream = p.open(format=
p.get_format_from_width(wf.getsampwidth()),
channels=wf.getnchannels(),
rate=wf.getframerate(),
output = True
)
data = wf.readframes(chunk)
while data != '':
stream.write(data)
data=wf.readframes(chunk)