Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I would like to add pico2wave tts #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions OPTIONAL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## TTS: Pico2Wave

### Installation

sudo apt-get install libttspico-utils

### Configuration

Change "Python projects/config.yml" tts parameters to "pico2wave" for activate it

## Play from Youtube

### Installation

Install youtube-dl (download m4a)
https://github.com/rg3/youtube-dl/blob/master/README.md#how-do-i-update-youtube-dl

sudo wget https://yt-dl.org/latest/youtube-dl -O /usr/local/bin/youtube-dl
sudo chmod a+x /usr/local/bin/youtube-dl
hash -r

apt-get install ffmpeg

### Use it from PyCmd

python2.7 PiCmd.py -c youtube -y Zs81kDyjTP8
(-y is VIDEO_YOUTUBE_ID parameter)
13 changes: 11 additions & 2 deletions Python projects/PiCmd.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


from multiprocessing import Process, Queue
import subprocess
import time
import fileinput
import thread
Expand Down Expand Up @@ -32,6 +33,7 @@
ser=""
matrix = 0
expression = ""
youtube_code = ""

# # thread function (NOT USED)
# def dispach_UI():
Expand Down Expand Up @@ -150,7 +152,7 @@ def get_languaje():
print "laguaje param error"

def get_mouth_expression():
global expression
global expression

try:
arg = scan_argument(idx)
Expand All @@ -162,6 +164,9 @@ def get_mouth_expression():
except:
print "expression param error"

def get_youtube_code():
global youtube_code
youtube_code = scan_argument(idx)

def get_mouth_matrix():
global matrix
Expand Down Expand Up @@ -268,8 +273,9 @@ def CommandOK_Action():
HeadServo.SetMouth(0x1B1F0E04)
elif cmd == "listen":
listen_thd = Qbo.StartBack()
elif cmd == "youtube":
result = subprocess.call("youtube-dl --extract-audio --audio-format wav -o \"cancion.%(ext)s\" https://www.youtube.com/watch?v=" + youtube_code + " ; aplay cancion.wav -D convertQBO", shell = True)


else:
print "Command error. Type ? to help"

Expand All @@ -283,6 +289,7 @@ def CommandOK_Action():
"-l" : get_languaje,
"-m" : get_mouth_matrix,
"-e" : get_mouth_expression,
"-y" : get_youtube_code,
"?" : help,
"help" : help,
"-h" : help,
Expand All @@ -294,6 +301,7 @@ def CommandOK_Action():
"voice",
"mouth",
"listen",
"youtube",
}


Expand Down Expand Up @@ -382,6 +390,7 @@ def CommandOK_Action():
color = ""
matrix = 0
expression = ""
youtube_code = ""

# escanea los argumentos de la linea de comandos
for word in line.split():
Expand Down
2 changes: 1 addition & 1 deletion Python projects/config.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{age: 1, languaje: english}
{age: 1, languaje: english, tts: espeak}
47 changes: 27 additions & 20 deletions Python projects/say.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,32 @@


def SayFromFile():
print("Opening FIFO...")
while True:
fifo = os.open(FIFO_say, os.O_RDONLY)
data = os.read(fifo, 100)
os.close(fifo)

if data:
config = yaml.safe_load(open("/home/pi/Documents/Python projects/config.yml"))

print('Read: "{0}"'.format(data))
if config["languaje"] == "english":
speak = "espeak -ven+f3 \"" + data + "\" --stdout | aplay -D convertQBO"
elif config["languaje"] == "spanish":
speak = "espeak -v mb-es2 -s 120 \"" + data + "\" --stdout | aplay -D convertQBO"
print "Talk: " + speak

result = subprocess.call("../deamonsScripts/QBO_listen stop", shell = True)
result = subprocess.call(speak, shell = True)
result = subprocess.call("../deamonsScripts/QBO_listen start", shell = True)
print("Opening FIFO...")
while True:
fifo = os.open(FIFO_say, os.O_RDONLY)
data = os.read(fifo, 100)
os.close(fifo)

if data:
config = yaml.safe_load(open("/home/pi/Documents/Python projects/config.yml"))

print('Read: "{0}"'.format(data))
if config["tts"] == "espeak":
if config["languaje"] == "english":
speak = "espeak -ven+f3 \"" + data + "\" --stdout | aplay -D convertQBO"
elif config["languaje"] == "spanish":
speak = "espeak -v mb-es2 -s 120 \"" + data + "\" --stdout | aplay -D convertQBO"
elif config["tts"] == "pico2wave":
if config["languaje"] == "english":
speak = "pico2wave -l en-GB -w /tmp/qbtmp.wav \"" + data + "\" && aplay /tmp/qbtmp.wav -D convertQBO"
elif config["languaje"] == "spanish":
speak = "pico2wave -l es-ES -w /tmp/qbtmp.wav \"" + data + "\" && aplay /tmp/qbtmp.wav -D convertQBO"

print "Talk: " + speak

result = subprocess.call("../deamonsScripts/QBO_listen stop", shell = True)
result = subprocess.call(speak, shell = True)
result = subprocess.call("../deamonsScripts/QBO_listen start", shell = True)

#============================================================================================================

Expand All @@ -46,4 +53,4 @@ def SayFromFile():
# raise

while True:
SayFromFile()
SayFromFile()