Reputation: 1
For the past few days I have been trying to trying to get this "simple" voice synth to work. The code came in a manual for the raspberry pi. This is my first time really getting into python so my head is kinda spinning. Here is the code:
import subprocess
subprocess.call(["espeak"])
from espeak import espeak
from tkinter import *
from datetime import datetime
def hello_world():
espeak.synth("Hello World")
def time_now():
t = datetime.now().strftime("%K %M")
espeak.synth("The time is %s"%t)
def read_text():
text_to_read = input_text.get()
espeak.synth(text_to_read)
def root_Tk():
root.title("voice box")
input_text = StrinVar()
box = Frame(root, height = 200, width =500)
box.pack_propagate(0)
box.pack(padx = 5, pady =5)
Label(box, text="Enter Text").pack()
entry_text = Entry(box, exportselection =0, textvariable = input_text,)
entry_text.pack()
entry_ready = Button(box, text = "Read this", command = read_text)
entry_ready.pack()
hello_button = Button(box, text = "Hello World", command = hello_world)
hello_button.pack()
time_button = Button(box, text = "What's the time?", command = time_now)
time_button.pack()
root.mainloop()
and this is the error message when I run it:
Traceback (most recent call last): File "/home/pi/espeak.py", line 4, in from espeak import espeak File "/home/pi/espeak.py", line 4, in from espeak import espeak ImportError: cannot import name 'espeak'
Any help on this matter would be greatly appreciated, I have a feeling im just making a simple newbie mistake. Hopefully I was able to post it to the forum correctly, the bottom part of the code is in line with the rest, but for some reason it's slightly off on here...
Upvotes: 0
Views: 5115
Reputation: 2693
Install espeak and the python-espeak package in Ubuntu with apt-get.
sudo apt-get install espeak python-espeak
In your .py file:
from espeak import espeak
def hello_world():
espeak.synth("Hello World")
....
This will fix your issue!
Ref: http://www.devdungeon.com/content/text-speech-python-espeak
Bonus: You can consider using gTTS instead of espeak as it maintained under Python package index.
Upvotes: 2