52 lines
1.2 KiB
Python
52 lines
1.2 KiB
Python
import os
|
|
import subprocess
|
|
|
|
|
|
import logging
|
|
import sys
|
|
from src.mplayer import Mplayer
|
|
|
|
#logging.basicConfig()
|
|
#logger = logging.getLogger("kalliope")
|
|
|
|
|
|
class Pico2wave():
|
|
|
|
def __init__(self):
|
|
self.language = "fr-FR"
|
|
|
|
def say(self, words):
|
|
"""
|
|
:param words: The sentence to say
|
|
"""
|
|
self.file_path = "/tmp/nemo.tts"
|
|
self.generate_audio_file(words)
|
|
self.play_audio()
|
|
|
|
def play_audio(self):
|
|
"""
|
|
Play the audio file
|
|
"""
|
|
Mplayer.play(self.file_path)
|
|
#self.player.play(self.file_path)
|
|
|
|
def generate_audio_file(self,words):
|
|
self.path = "/usr/bin/pico2wave"
|
|
|
|
# pico2wave needs that the file path ends with .wav
|
|
tmp_path = self.file_path+".wav"
|
|
pico2wave_options = ["-l=%s" % self.language, "-w=%s" % tmp_path]
|
|
|
|
final_command = list()
|
|
final_command.extend([self.path])
|
|
final_command.extend(pico2wave_options)
|
|
final_command.append(words)
|
|
|
|
logging.debug("[Pico2wave] command: %s" % final_command)
|
|
|
|
# generate the file with pico2wav
|
|
subprocess.call(final_command)
|
|
|
|
# remove the extension .wav
|
|
os.rename(tmp_path, self.file_path)
|