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

Added ability to set a default play command #9

Open
wants to merge 2 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
1 change: 1 addition & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from responsive_voice import ResponsiveVoice

engine = ResponsiveVoice()
engine.default_play_cmd = "mpg123 -o pulse -q %1"
engine.say("hello world")
engine.say("hello world",
gender=ResponsiveVoice.MALE,
Expand Down
10 changes: 7 additions & 3 deletions responsive_voice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ class ResponsiveVoice:
GREEK = "el-GR"
JAPANESE = "ja-JP"

default_play_cmd = "mpg123 -q %1"

def __init__(self, lang=None, gender=None,
pitch=0.5, rate=0.5, vol=1,
voice_name="", service="", key=None):
voice_name="", service="", key=None, default_play_command=default_play_cmd):
self.pitch = pitch
self.rate = rate
self.vol = vol
Expand All @@ -74,9 +76,11 @@ def __init__(self, lang=None, gender=None,
# key extracted from wordpress plugin - FQ9r4hgY
# alternate key from Bundler - HY7lTyiS
self.key = key or "FQ9r4hgY"
default_play_cmd = default_play_command


@staticmethod
def play_mp3(mp3_file, play_cmd="mpg123 -q %1", blocking=False):
def play_mp3(mp3_file, play_cmd=default_play_cmd, blocking=False):
# TODO support windows shell commands

if playsound is not None:
Expand Down Expand Up @@ -121,7 +125,7 @@ def get_mp3(self, sentence, mp3_file=None, pitch=None, rate=None,

def say(self, sentence, mp3_file=None, pitch=None, rate=None, vol=None,
gender=None,
play_cmd="mpg123 -q %1", blocking=True):
play_cmd=default_play_cmd, blocking=True):
filename = self.get_mp3(sentence, mp3_file, pitch=pitch,
rate=rate, vol=vol, gender=gender)
self.play_mp3(filename, play_cmd, blocking)