pi-top / pi-top-Python-SDK

pi-top's Python SDK (pitop package)
Apache License 2.0
27 stars 4 forks source link

Add text-to-speech functionality #376

Open duwudi opened 3 years ago

duwudi commented 3 years ago

Use pi-top's onboard speaker to interact with the user via speech - particularly useful/interesting for robotics applications but can also have a lot of value for simpler Foundation Kit projects.

See old library created here that uses espeak.

Options

Google TTS

Usage:

from gtts import gTTS
import pygame
from io import BytesIO

pygame.init()

tts = gTTS(text=text, lang='en')
fp = BytesIO()
tts.write_to_fp(fp)
fp.seek(0)

pygame.mixer.init()
pygame.mixer.music.load(fp)
pygame.mixer.music.play()

eSpeak

Pico TTS

Installation

wget http://ftp.us.debian.org/debian/pool/non-free/s/svox/libttspico0_1.0+git20130326-9_armhf.deb
wget http://ftp.us.debian.org/debian/pool/non-free/s/svox/libttspico-utils_1.0+git20130326-9_armhf.deb
sudo apt-get install -f ./libttspico0_1.0+git20130326-9_armhf.deb ./libttspico-utils_1.0+git20130326-9_armhf.deb

Usage:

pico2wave -w lookdave.wav "Hello, world!" && aplay lookdave.wav

pyttsx3

Installation

sudo apt install espeak
pip3 install pyttsx3

Usage

import pyttsx3
engine = pyttsx3.init()
engine.say("Hello, world!")
engine.runAndWait()

Microsft TTS

Amazon Polly

Festival

Installation

sudo apt-get install festival
pip3 install pyfestival

Mozilla TTS

Mimic1 from Mycroft.ai

Usage

./mimic -t "Hello"

# change voice
./mimic -t "Hello" -voice kal16
angusjfw commented 2 years ago

I got pretty good results using festival with a plug-in voice as described here.

sudo apt-get install -y festival festvox-us-slt-hts
festival -b '(voice_cmu_us_slt_arctic_hts)' \
    '(SayText "The temperature is 22 degrees centigrade and there is a slight breeze from the west.")'

The python lib actually binds to the c++ lib, subprocesses are only used for converting to mp3 I think. It gives me an ImportError when I try to use it though.

angusjfw commented 2 years ago

Similar results with flite, which mimic is based on:

sudo apt install flite
flite -voice slt -t "The Raspberry Pi is a great Maker platform!"

Didn't try the python bindings

duwudi commented 2 years ago

I got pretty good results using festival with a plug-in voice as described here.

This one sounds pretty good actually, let's just use that!

duwudi commented 2 years ago

The python lib actually binds to the c++ lib, subprocesses are only used for converting to mp3 I think. It gives me an ImportError when I try to use it though.

Can we still use the plugin if using the python library?

duwudi commented 2 years ago

It gives me an ImportError when I try to use it though.

Yeah I've got the same thing, the pypy package is not actually up to date with the repo though - importing from the pip-installed version gives this error:

Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/festival.py", line 3, in <module>
    from . import _festival
ImportError: attempted relative import with no known parent package

Installing from the repo directly gives this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.7/site-packages/festival.py", line 6, in <module>
    import _festival
ImportError: /lib/arm-linux-gnueabihf/libestools.so.2.5: undefined symbol: omp_get_thread_num

Not sure how to fix this, any ideas?

duwudi commented 2 years ago

Didn't try the python bindings

Can't get this one building either, fails on python3 setup.py build even after installing swig

duwudi commented 2 years ago
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.7/site-packages/festival.py", line 6, in <module>
    import _festival
ImportError: /lib/arm-linux-gnueabihf/libestools.so.2.5: undefined symbol: omp_get_thread_num

Adding this fix https://github.com/techiaith/pyfestival/pull/9 gets the python bindings working. The plan is to fork this repo and manage it ourselves since it's relatively simple