1

Hi! So my problem is: I'm trying to make my Pi 3 speaking, I looked up multiple articles, but none of them could help unfortunately.


My code line: from espeak import espeak
And I get an error:
File "/home/pi/ttstest.py", line 9, in
from espeak import espeak
ModuleNotFoundError: No module named 'espeak'

I'm using Raspbian on Raspberry Pi 3.
I have espeak and python-espeak istalled as well.
I used this code in terminal to test the espeak: espeak "Hello World" 2>/dev/null It works, I'm hearing the speech.

If someone please could help me, I would be more than grateful! :)

leonheess
  • 16,068
  • 14
  • 77
  • 112
ChrisHun
  • 13
  • 1
  • 4
  • 1
    Have you installed it using Pip? Have you verified that it is being installed to the version of Python you are running here? – clubby789 Jan 22 '20 at 12:05
  • A simple test to check if the version of Python you are running has it installed is to use `python -m pip freeze` and make sure espeak appears in the list. – Tim Jan 22 '20 at 13:45
  • Problem solved! Yes, the problem was with the versions, so I downloaded the correct versions, and it's working just fine. Thank you 4 the help! :) – ChrisHun Jan 22 '20 at 13:56

1 Answers1

6

Method using espeak-python

Install espeak-python

sudo apt install espeak-python

Then,you can play text as following

from espeak import espeak

espeak.set_voice("en")

espeak.synth("hello")

while espeak.is_playing:
    pass

for more information using this method click here

Method using espeak

Alernatively,You can run play using espeak command in python

install espeak

sudo apt install espeak

Then,you can play text as following

import os
text="this is demo text"
os.system('espeak "'+text+'"')

Here text is wrapped with double quotes because without it the espeak command will only take first word in this case i.e 'this'

You can also define other arguments as in terminal like speed,voice,word gap etc.

Example using speed of 200 WPM(words per minute)

import os
text="this is demo text"
os.system('espeak -s 200 "'+text+'"')

You may also directly pass string inside double quotes

import os
os.system('espeak -s 200 "this is demo text"')

for more information using this method click here