-
Notifications
You must be signed in to change notification settings - Fork 7
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
use espeak cmd instead of espeak-ng on macOS #9
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# -*- coding: utf-8 -*- | ||
|
||
# | ||
# Copyright 2017 Guenter Bartsch | ||
|
@@ -20,38 +20,39 @@ | |
import logging | ||
import subprocess | ||
import tempfile | ||
import platform | ||
|
||
class ESpeakNG(object): | ||
|
||
def __init__(self, | ||
volume = 100, | ||
def __init__(self, | ||
volume = 100, | ||
audio_dev = None, | ||
word_gap = -1, # ms | ||
capitals = 0, # indicate capital letters with: 1=sound, 2=the word "capitals", higher values indicate a pitch increase (try -k20). | ||
line_length = 0, # Line length. If not zero, consider lines less than this length as end-of-clause | ||
pitch = 50, # 0-99 | ||
speed = 175, # approx. words per minute | ||
voice = 'english-us'): | ||
speed = 175, # approx. words per minute | ||
voice = 'en'): | ||
|
||
|
||
self._volume = volume | ||
self._audio_dev = audio_dev | ||
self._word_gap = word_gap | ||
self._capitals = capitals | ||
self._volume = volume | ||
self._audio_dev = audio_dev | ||
self._word_gap = word_gap | ||
self._capitals = capitals | ||
self._line_length = line_length | ||
self._pitch = pitch | ||
self._speed = speed | ||
self._voice = voice | ||
self._pitch = pitch | ||
self._speed = speed | ||
self._voice = voice | ||
|
||
def _espeak_exe(self, args, sync=False): | ||
cmd = ['espeak-ng', | ||
cmd = ['espeak' if platform.system()=='Darwin' else 'espeak-ng', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I searched in https://brew.sh/ and found espeak, but no espeak-ng, I guess you can only brew install espeak. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a hack to me. We could look into auto-detecting the availability of first espeak-ng and, as a fallback espeak on a system and use the best available option. |
||
'-a', str(self._volume), | ||
'-k', str(self._capitals), | ||
'-l', str(self._line_length), | ||
'-p', str(self._pitch), | ||
'-s', str(self._speed), | ||
'-v', self._voice, | ||
'-b', '1', # UTF8 text encoding | ||
'-k', str(self._capitals), | ||
'-l', str(self._line_length), | ||
'-p', str(self._pitch), | ||
'-s', str(self._speed), | ||
'-v', self._voice, | ||
'-b', '1', # UTF8 text encoding | ||
] | ||
|
||
if self._word_gap>=0: | ||
|
@@ -102,11 +103,11 @@ def say(self, txt, sync=False): | |
|
||
return self._espeak_exe(args, sync=sync) | ||
|
||
def synth_wav(self, txt, fmt='txt'): | ||
def synth_wav(self, txt, file=None, fmt='txt'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a option to save to a non-temp file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lacks implementation, doesn't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. implemented in line#110 |
||
|
||
wav = None | ||
|
||
with tempfile.NamedTemporaryFile() as f: | ||
with (open(file, 'w') if file else tempfile.NamedTemporaryFile()) as f: | ||
|
||
|
||
if fmt == 'xs': | ||
|
@@ -120,6 +121,9 @@ def synth_wav(self, txt, fmt='txt'): | |
|
||
self._espeak_exe(args, sync=True) | ||
|
||
if file: | ||
return | ||
|
||
f.seek(0) | ||
wav = f.read() | ||
|
||
|
@@ -135,7 +139,7 @@ def g2p(self, txt, ipa=None, tie=None): | |
args.append('--ipa=%s' % ipa) | ||
else: | ||
args.append('-x') | ||
|
||
if tie: | ||
args.append('--tie=%s' % tie) | ||
|
||
|
@@ -146,7 +150,7 @@ def g2p(self, txt, ipa=None, tie=None): | |
for line in self._espeak_exe(args, sync=True): | ||
|
||
logging.debug(u'line: %s' % repr(line)) | ||
|
||
phonemes += line.decode('utf8').strip() | ||
|
||
return phonemes | ||
|
@@ -199,7 +203,7 @@ def volume(self, v): | |
|
||
@property | ||
def audio_dev(self): | ||
return self._audio_dev | ||
return self._audio_dev | ||
@audio_dev.setter | ||
def audio_dev(self, v): | ||
self._audio_dev = v | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's no voice named 'english-us' by espeak-ng default installation, you can set it to 'en' or 'en-us'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not change indentation. If voice names have changed, I guess we need to update tests as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are no indentations changed, only some white space trimmed at line end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same problem here. should switch to
en-us