0

I'm running a Raspberry Pi4 with Python 3.7 and pyttsx3.

I'm planning to use pyttsx3 to verbally respond to "commands" I issue. I also plan to visualise the output speech on a neopixel strip (think "Close Encounters" on a miniature scale.) The visualisation is not the problem though.

My problem is, how do I get the output from pyttsx3 into a variable so I can pass it to my DSP?

I know that I can pass the to a file:

import pyttsx3
engine = pyttsx3.init() # object creation
"""Saving Voice to a file"""
engine.save_to_file('Hello World', 'text.mp3')
engine.runAndWait()

& I know I can read the file but that creates a latency.

I want the speech and twinkly lights to coincide and I know I can play the wav file but I'd like something more "real time".

Does anyone have any suggestions please?

  • It doesn’t appear that you can easily get sample-by-sample / frame-by-frame audio directly from `pyttsx3`. You are best using `Pyaudio` to play the output file of `pyttsx3`. You can then use either frequency or amplitude data to control your neopixels – fdcpp Oct 23 '20 at 07:26
  • Although this is not real-time in the sense that audio is output at point of calculation, latency between file write / read should be fairly minimal. In fact, `pyttsx3` is likely to render all the audio before output, so it is never strictly in 'real-time'. – fdcpp Oct 23 '20 at 07:44
  • For `Pyaudio` > `Neopixels`, I'm sure you can [find inspiration](https://github.com/spiffomatic64/neopixel_fft) from [GitHub](https://github.com/johnkimdinh/audio-reactive-led-strip) – fdcpp Oct 23 '20 at 07:47
  • Another possible option is to use [eSpeak](https://github.com/espeak-ng/espeak-ng#documentation) directly in a C program. [See here](https://github.com/espeak-ng/espeak-ng/issues/317) – fdcpp Oct 23 '20 at 08:05
  • Thank you for your input folks. Kind of confirming my suspicions. 1: pyttsx3 to a file 2: Read the file 3: DSP and aplay the file simultaneously. I'm planning to use brightness for amplitude and colour for frequency. I have the neopixels figured out. I dump index, r,g,b data out from the Pi across a UART bus to an Adafruit TrinkteM0 then let it do the display work. – Ian Scott Moyes Oct 23 '20 at 09:21

0 Answers0