Notifications
Clear all

eSpeak on a Raspberry Pi 4

116 Posts
9 Users
30 Likes
20.6 K Views
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1038
 
Posted by: @robo-pi

eSpeak Part(2): eSpeak in Python is out.

I have been following along on the Jetson Nano, and made this discovery.

I did not get any lines of "extra" text when I executed the code on your line 14 (cmdLine.run(command, shell=True).  But when I commented out line 14 and un-commented line 15, just to see what the difference might be, then ran the program I got an error from Python and the program did not execute.  Have not tried the same thing yet on my Pi4, but will shortly.

SteveG


   
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
Topic starter  
Posted by: @codecage

I have been following along on the Jetson Nano,

Yes, there will be quirky little differences, unfortunately.   In part because they are different machines.  But also in part, because they are running different OS.   The Rpi is running Raspbian, and the Nano is running Ubuntu 18.04 that has even been modified for NVIDIA.   I actually have Ubuntu 18.04 installed on a Rpi system card, but even that has little differences from the Ubuntu running on the Nano.

So there are always those little quirks that need to be worked out.

I'm currently moving over to using Python's Tkinter GUI so I can run a regular program with actual GUI windows.   That's proving to be a major educational side-track as well.   Although one that will certainly pay off in the long haul.  I don't want to have to be running everything from the Python IDE and terminal window for the rest of my life.

The GUI project is coming along quite fast actually.  In part, because I've worked with Windows Forms before and have a good idea about all the widgets, even though they don't call them widgets in Windows.  It's still basically the same thing.  Although they are programmed differently.  Windows Forms are much easier to use to be sure.  More flexible too.  At least I think so.  Can't say for certain since I don't really know all the secrets of Tkinter yet.

I'm anxious to move on to getting Pocket Sphinx completely squared away next.  But I'd like to finish this GUI dictionary program first.  Especially since it seems to be coming along fairly quickly so far.  This will make editing dictionaries much easier.

DroneBot Workshop Robotics Engineer
James


   
codecage reacted
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
Topic starter  

This is just a very short and quick video to show what I'm working on in terms of the GUI interface to Alysha and the eSpeak dictionary. I don't show how I wrote this app because it's a huge amount of boring code. 🤣 

I'm might make a video going over the code briefly at some point if enough people request it.   It's all done using Python and tkinter.   Most of the code for eSpeak and the Dictionary is what we already did before.

Anyway, here's a short glimpse of what it's like.   It's not even completely finished yet.  But I need to take a break from sitting at computers for a while, so I thought I'd share this while it's hot off the press. 😎 

 

DroneBot Workshop Robotics Engineer
James


   
codecage reacted
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1038
 

@robo-pi

Keep up the good work James!

SteveG


   
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
Topic starter  
Posted by: @codecage

Keep up the good work James!

I wish I could.  But the new tires I ordered for my antique car came in yesterday!  😎 

So it's time to put the computers away for a while and return to the real world.

So it's going to be a while before I get to do much more done toward this AI project.

I have a lot of work to do on my car.  I'd like to put it on the road this summer.  I have the entire interior of it out of it as I'm redoing the interior. 

By the time I get back into computing I'll have to relearn everything. 🤣 

That's part of the reason I made these videos!  I'll probably end up having to watch them myself to remind me of what I've done up to this point.

I probably should make a video on tkinter so I don't forget how to do that too. 😮 

DroneBot Workshop Robotics Engineer
James


   
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
Topic starter  

I'm finally FREE from the IDE!  Yippee!  😎 

I had to do it!  Before I could go work on my car I had to figure out why I couldn't run the GUI program from a desktop icon.  I discovered that I simply had to give the full path name to objects like Alysha's picture.  Even though it was in the directory where the Python program resides, it still had to have the full address for some reason.

It any case, I finally have a stand-alone GUI program I can run without having to do it from CODE-OSS.

Of course I'll still need to use CODE-OSS to continue to write and develop the program further.   But it feels good to have the GUI up and running as a stand-alone Python program.

Things are really starting to shape up.

Now I can go work on "Joyce" in peace. 🤣 

"Joyce" is the name of my 47' Chevy. 

It's also my sister's name.  And guess what?

My sister was also born in '47.  She also gave me some money toward the car for my birthday back when I bought the car.   So my life is filled with women.   Alysha is talking over my computer.   And Joyce has taken over the garage.

Now if I can find a live woman to take over my kitchen I'd be in great shape.

It's going to be a very long time before Alysha will be preparing any meals. She doesn't even have a body yet.

DroneBot Workshop Robotics Engineer
James


   
codecage reacted
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1038
 

@robo-pi

Are you going to share, or are we going to have to live with the CODE-OSS route? 🙄 

SteveG


   
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
Topic starter  

@codecage

Do I have to teach everything?  Who's going to teach me?

I was a bad boy this morning and did a lot of coding toward the Dictionary App. 😊 

I am NOT the world's best Python coder.  In fact, true confessions be known, I was having quite a bit of difficulty with accessing various different tkinter objects from different parts of the program.  I spent HOURS getting it all sorted out.    And while I feel that I have finally gotten it pretty well sorted, I'm still not perfectly clear on the best way to do things.

In fact, I ended up with two versions of the program.  An object-oriented version and structured-programming version.

The object-oriented approach:

My first solution that actually worked was to use a ton of the "self" referencing keyword.

I realized that if I defined things using

self.thing = definition

I could then access it from any other method using the "self" keyword.

One problem with this was that I ended up having to use the "self" keyword a gazillion times.

The program worked, but it was getting ugly with all the self.objects references.  And I couldn't remove them as the program simply wouldn't work without them,...

Until,....

The structured-programming approach:

Then I went back and realized that if I move various methods around in the overall program I could eliminate a bunch of the "self" keywords, as the objects would naturally belong to the methods I was attempting to access them from.  (it's actually a very long story)

But in the end, by writing better-structured code, I was able to eliminate quite a few "self" statements.  I also like this code better, but I'm not sure how well this will hold up as the program continues to grow.  I still may have trouble accessing various objects as I continue to add more methods.   And that will force me to having to go back to using the "self" attribute again.

In the end, I don't even know which method is preferred, or if there even is a preferred method.  I came from a structured programming background, and everything I know about Python is self-learned.   So I'm not sure if I'm even dealing with object-oriented programming in a rational way.

All I know is that I have a program that works.  And I have two different versions of it.  I prefer the structured-programming style, although this obviously also include object-oriented programming.  But the code tends to be cleaner, and it ends up with less use of the "self" keyword.

Summary:

I have very little clue what I'm doing.  But I somehow ended up with a working program written in two different ways. 🤣 

Although, I'll be moving forward with the structured-programming style as I like it better and it does seem to produce simpler code with with less need for using "self".

Some people say that as long as it runs that's all that matters.   Other's will have you flogged if you don't do it their way. 🤣 

Moving Forward:

Now that I have the program cleaned up and running the way I want it, I'm now moving forward to start to actually work with programming more detailed dictionary functions.

I'm having some problems due to not understanding how various Python objects actually work.

I'm trying to work with Python Lists and a Tkinter Text Widget and I'm having difficulty getting the text from the list into the Text widget without also getting braces and other unwanted junk.

So I guess what I need to work on now is learning exactly how to do that.  I'll be manipulating the text quite a bit, so I'm going to need to understand how this works in pretty much detail without confusion.  I'm not there yet.

But yeah, if I ever manage to get it all ironed out, I'll probably make a video on it at that time.

In the meantime I better go out and mow the lawn!  I have to do it with a push mower because my riding mower needs to be repaired!  Yet another tractor to work on!

 

DroneBot Workshop Robotics Engineer
James


   
codecage reacted
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
Topic starter  

Maybe someone can help me with this?

Here's a small Python program using a tkinter Text box and a Python List of lines.

 

from tkinter import *

win_main = Tk()

lines = ["First line \n", "Second Line \n", "Third Line \n"]

txtBox_1_dict = Text(win_main, height=10, width=20, padx=25, font=("Arial", 18))
txtBox_1_dict.grid(row=1, column=0)
txtBox_1_dict.insert(END,lines)


win_main.mainloop()

 Here's the resulting Text Box window:

tk window

Question.  Is there any EASY way to keep it from including the {} ?

I just want the text from the list elements, not the braces.

How do transfer the text only to the Text Box widget?

I'll also want to add line numbers before each entry.

And later I'll need to be able to access and edit each line in the Text Box widget. 

I'm not sure how to this EASILY.

I know I can do it with a ton of code that manipulates all these strings, but surely that's kind of the old-fashioned way.

Python brags about being able to do things easily, so how is this done easily? 

Thanks

DroneBot Workshop Robotics Engineer
James


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1038
 
Posted by: @robo-pi

Do I have to teach everything?  Who's going to teach me?

OK, I guess I need to jump into the tkinter sand box.   I guess I am getting quite heavy on your coat tails! 😎 

SteveG


   
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
Topic starter  

@codecage

I'll be glad to share my code when I get it all ironed out. 😊 

Currently it's a mess and in dire need of much improvement.

Having said that, I am well pleased with how well it's improving.   The successes are outweighing the failures thus far.  But I still have a long way to go to get it to do exactly what I would like for it to do.   Mostly having to do with interfacing lists of text with the tkinter Text Widgets.  Once I get that well under control I should be home free.

DroneBot Workshop Robotics Engineer
James


   
ReplyQuote
triform
(@triform)
Member
Joined: 5 years ago
Posts: 324
 

@robo-pi

Hi James,

The best way is to iterate the array with a 'for' loop.  In the loop you can format the line however you want it before calling the insert method.

Scott

 


   
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
Topic starter  

@triform

Thanks Scott.  I just figured that out.  Although it was a bit more complicated.  The Text.insert() method needs to use floats and not integers.   That's what was throwing me for a loop.  Plus the floats are used to index the texts in a very unique way.  I just now learned how to do this.

Here's the code that works. 

 

from tkinter import *

win_main = Tk()

lines = ["First line \n", "Second Line \n", "Third Line \n"]
print (lines[0])

txtBox_1_dict = Text(win_main, height=10, width=20, padx=25, font=("Arial", 18))
txtBox_1_dict.grid(row=1, column=0)

for n in range(1,len(lines)+1):
    index = n + 0.0
    txtBox_1_dict.insert(index,str(n) + ". " +lines[n-1])
    print(index)

win_main.mainloop()

  And here's the output:

 

tk window 2

Now I need to figure out how to read from the Text Box and put the modified text back into a list. 

DroneBot Workshop Robotics Engineer
James


   
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
Topic starter  

Actually it makes more sense to do it as follows:  

 

from tkinter import *

win_main = Tk()

lines = ["First line \n", "Second Line \n", "Third Line \n"]
print (lines[0])

txtBox_1_dict = Text(win_main, height=10, width=20, padx=25, font=("Arial", 18))
txtBox_1_dict.grid(row=1, column=0)

for n in range(len(lines)):
    index = n + 1.0
    txtBox_1_dict.insert(index,str(n+1) + ". " +lines[n])
    print(index)

win_main.mainloop()

This produces the same result but makes for less confusing code.

DroneBot Workshop Robotics Engineer
James


   
ReplyQuote
triform
(@triform)
Member
Joined: 5 years ago
Posts: 324
 

@robo-pi

Yeah, the number is line.char_ndx.  It gives you a way to do more detailed line manipulation.  The Tk Text widget is actually a great one to use.  I did a good bit of Tcl/Tk front-ends for several apps for myself and on the job. It also has "Tags" that are good for line/word coloring or font setting in the widget. 

Scott

 


   
ReplyQuote
Page 7 / 8