I have just come back from our monthly Pi gathering at our local library during which one of the Library staff asked if I could help them with the Shakespeare Random Insults Generator for an event in the Library. Basically what they want is to have this installed on the Libraries demo Raspberry Pi and visitors could 'easily' receive an insult from the man himself
During the Pi day they managed to find a pre-written version of the python script and towards the end of the session I and one of the attendees gt it running but wanted to make it a little more user friendly by being able to simply start it by clicking on a desktop icon. This is where it started getting complicated..
Now at home I have managed to make the program executable using chmod +x and now when double clicking on the .py icon an 'Execute File' window opens with options to Execute, Execute in Terminal, Open, Close. The only option that seems to run the program is 'Execute in Terminal'.
What I want to be able to do now though is rather than read the insult I want the Pi to speak it.
I have installed Pico Text to Speach and tested that it works by providing the correct arguments:
The existing program works by picking a random word from each of three .csv files containing Shakespearian insulting words It then simply prints them to the screen.
Code: Select all
pico2wavw -w hello.wav "Hello World" && aplay hello.wav
I guess what I need to do is to create a file containing the phrase made up in the form of a list using the three components along with the initial greeting and then supply Pico the generated text file?
Question is how?
Here is the original code:
Code: Select all
#!/usr/bin/env python import random from time import sleep column1= column2= column3= # Read contents of column1.txt and add the contents to the 1st list file1 = open("column1.txt","r") line = file1.readline() while line != "": column1.append(line) line = file1.readline() file1.close() # Read contents of column2.txt and add the contents to the 2nd list file2 = open("column2.txt","r") line = file2.readline() while line != "": column2.append(line) line = file2.readline() file2.close() # Read contents of column3.txt and add the contents to the 3rd list file3 = open("column3.txt","r") line = file3.readline() while line != "": column3.append(line) line = file3.readline() file3.close() print("Thou art aye " + column1[random.randint(0,49)] + (" ") + column2[random.randint(0,49)] + (" ") + column3[random.randint(0,49)]) sleep(2)