Skip to content
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
7 changes: 7 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ def test_speakers():
except Exception as e:
print("error: %r" % (e,))
return False

print("%s -> %s @ 2x" % (locality, voice.value))
try:
PiperSpeaker(voice=voice, speed=2).say(text)
except Exception as e:
print("error: %r" % (e,))
return False
finally:
print("--------")
return True
Expand Down
9 changes: 9 additions & 0 deletions yapper/speaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def __init__(
quality: Optional[PiperQuality] = None,
show_progress: bool = True,
volume: float = 1.0,
speed: float = 1.0,
):
"""
Parameters
Expand All @@ -134,6 +135,9 @@ def __init__(
volume : float, optional
volume to play the wav file at, between 0.0 and 1.0
(defaults to 1.0)
speed : float, optional
speed to play the wav file at (ex: 2 for 2x)
(defaults to 1.0 for 1x)
"""
assert isinstance(
voice, tuple(c.piper_enum_to_lang_code.keys())
Expand All @@ -149,6 +153,9 @@ def __init__(

self.volume = volume

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please remove the blank line, that will make a block of properties (volume and speed)

self.speed = speed
self.length_scale = str(1/self.speed)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

please remove the self.speed = speed line and set length_scale directly


def text_to_wave(self, text: str, file: str):
"""Saves the speech for the given text into the given file."""
subprocess.run(
Expand All @@ -161,6 +168,8 @@ def text_to_wave(self, text: str, file: str):
"-f",
file,
"-q",
"--length-scale",
self.length_scale # this "length_scale" is just the speed value inverted

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

please remove the comment

],
input=text.encode("utf-8"),
stdout=subprocess.DEVNULL,
Expand Down