mirror of
https://github.com/nims11/IPod-Shuffle-4g.git
synced 2025-12-08 00:18:01 +09:00
Add support for using espeak when pico2wave not available.
This commit is contained in:
parent
7d628df3e8
commit
7d07168c0d
2 changed files with 32 additions and 7 deletions
|
|
@ -133,8 +133,10 @@ Original data can be found via [wayback machine](https://web.archive.org/web/201
|
||||||
# License and Copyright
|
# License and Copyright
|
||||||
|
|
||||||
```
|
```
|
||||||
Copyright (c) 2012-2016 ikelos, nims11, NicoHood
|
Copyright (c) 2012-2016 ikelos, nims11, ahippo, NicoHood, Thomas Hori
|
||||||
See the readme for credit to other people.
|
See the readme for credit to other people.
|
||||||
|
This software falls at least partly under the GNU GPL v2. Certain portions
|
||||||
|
fall under the following terms:
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
||||||
29
shuffle.py
29
shuffle.py
|
|
@ -51,13 +51,14 @@ def validate_unicode(path):
|
||||||
def exec_exists_in_path(command):
|
def exec_exists_in_path(command):
|
||||||
with open(os.devnull, 'w') as FNULL:
|
with open(os.devnull, 'w') as FNULL:
|
||||||
try:
|
try:
|
||||||
subprocess.call([command], stdout=FNULL, stderr=subprocess.STDOUT)
|
with open(os.devnull, 'r') as RFNULL:
|
||||||
|
subprocess.call([command], stdout=FNULL, stderr=subprocess.STDOUT, stdin=RFNULL)
|
||||||
return True
|
return True
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
class Text2Speech(object):
|
class Text2Speech(object):
|
||||||
valid_tts = {'pico2wave': True, 'RHVoice': True}
|
valid_tts = {'pico2wave': True, 'RHVoice': True, 'espeak': True}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def check_support():
|
def check_support():
|
||||||
|
|
@ -70,6 +71,13 @@ class Text2Speech(object):
|
||||||
else:
|
else:
|
||||||
voiceoverAvailable = True
|
voiceoverAvailable = True
|
||||||
|
|
||||||
|
# Check for espeak voiceover
|
||||||
|
if not exec_exists_in_path("espeak"):
|
||||||
|
Text2Speech.valid_tts['espeak'] = False
|
||||||
|
print "Error executing espeak, voicever won't be generated using it."
|
||||||
|
else:
|
||||||
|
voiceoverAvailable = True
|
||||||
|
|
||||||
# Check for Russian RHVoice voiceover
|
# Check for Russian RHVoice voiceover
|
||||||
if not exec_exists_in_path("RHVoice"):
|
if not exec_exists_in_path("RHVoice"):
|
||||||
Text2Speech.valid_tts['RHVoice'] = False
|
Text2Speech.valid_tts['RHVoice'] = False
|
||||||
|
|
@ -94,9 +102,17 @@ class Text2Speech(object):
|
||||||
text = unicode(text, 'utf-8')
|
text = unicode(text, 'utf-8')
|
||||||
lang = Text2Speech.guess_lang(text)
|
lang = Text2Speech.guess_lang(text)
|
||||||
if lang == "ru-RU":
|
if lang == "ru-RU":
|
||||||
|
if Text2Speech.valid_tts['RHVoice']:
|
||||||
return Text2Speech.rhvoice(out_wav_path, text)
|
return Text2Speech.rhvoice(out_wav_path, text)
|
||||||
else:
|
else:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
if Text2Speech.valid_tts['pico2wave']:
|
||||||
return Text2Speech.pico2wave(out_wav_path, text)
|
return Text2Speech.pico2wave(out_wav_path, text)
|
||||||
|
elif Text2Speech.valid_tts['espeak']:
|
||||||
|
return Text2Speech.espeak(out_wav_path, text)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
# guess-language seems like an overkill for now
|
# guess-language seems like an overkill for now
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
@ -113,6 +129,13 @@ class Text2Speech(object):
|
||||||
subprocess.call(["pico2wave", "-l", "en-GB", "-w", out_wav_path, unicodetext])
|
subprocess.call(["pico2wave", "-l", "en-GB", "-w", out_wav_path, unicodetext])
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def espeak(out_wav_path, unicodetext):
|
||||||
|
if not Text2Speech.valid_tts['espeak']:
|
||||||
|
return False
|
||||||
|
subprocess.call(["espeak", "-v", "english_rp", "-w", out_wav_path, unicodetext])
|
||||||
|
return True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def rhvoice(out_wav_path, unicodetext):
|
def rhvoice(out_wav_path, unicodetext):
|
||||||
if not Text2Speech.valid_tts['RHVoice']:
|
if not Text2Speech.valid_tts['RHVoice']:
|
||||||
|
|
@ -399,7 +422,7 @@ class Playlist(Record):
|
||||||
def set_master(self, tracks):
|
def set_master(self, tracks):
|
||||||
# By default use "All Songs" builtin voiceover (dbid all zero)
|
# By default use "All Songs" builtin voiceover (dbid all zero)
|
||||||
# Else generate alternative "All Songs" to fit the speaker voice of other playlists
|
# Else generate alternative "All Songs" to fit the speaker voice of other playlists
|
||||||
if self.voiceover and Text2Speech.valid_tts['pico2wave']:
|
if self.voiceover and (Text2Speech.valid_tts['pico2wave'] or Text2Speech.valid_tts['espeak']):
|
||||||
self["dbid"] = hashlib.md5("masterlist").digest()[:8] #pylint: disable-msg=E1101
|
self["dbid"] = hashlib.md5("masterlist").digest()[:8] #pylint: disable-msg=E1101
|
||||||
self.text_to_speech("All songs", self["dbid"], True)
|
self.text_to_speech("All songs", self["dbid"], True)
|
||||||
self["listtype"] = 1
|
self["listtype"] = 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue