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

use espeak cmd instead of espeak-ng on macOS #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
52 changes: 28 additions & 24 deletions espeakng/__init__.py
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
Expand All @@ -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'):
Copy link
Author

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'

Copy link
Owner

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.

Copy link
Author

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



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',
Copy link
Author

@hyansuper hyansuper Jan 30, 2021

Choose a reason for hiding this comment

The 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.
They seem to have some problems unresolved with espeak-ng on mac espeak-ng/espeak-ng#12.
I hope this will solve #1 , but I don't have a mac to confirm . I tested it on Ubuntu18 and Win10
I have a little robot project, it's tts function depends on py-espeak-ng. I hope it support all platforms

Copy link
Owner

Choose a reason for hiding this comment

The 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:
Expand Down Expand Up @@ -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'):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a option to save to a non-temp file

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lacks implementation, doesn't it?

Copy link
Author

Choose a reason for hiding this comment

The 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':
Expand All @@ -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()

Expand All @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down