I found an offline speech recognizer and tried to integrate a pyttsx3 module so that the word that I speak is also spoken by the pyttsx3. Basically it is a speech to text to speech code, but the engine.say does not seem to work. What should I do?
from vosk import Model, KaldiRecognizer
import pyaudio
import pyttsx3
model = Model(r"C:\Users\user\PycharmProjects\SpeechRecog\vosk-model-tl-ph-generic-0.6")
recognizer = KaldiRecognizer(model, 16000)
engine = pyttsx3.init()
mic = pyaudio.PyAudio()
stream = mic.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=8192)
stream.start_stream()
while True:
data = stream.read(4096)
if recognizer.AcceptWaveform(data):
word = recognizer.Result()
engine.say(word)
print(word)
print(word[14:-3])
I tried to insert the code of a text to speech into my speech recognizer code