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

support for --phoneme-input for having pure phonemes as input #403

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
7 changes: 7 additions & 0 deletions src/python_run/piper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def main() -> None:
action="store_true",
help="Stream raw audio to stdout",
)
parser.add_argument(
"-p",
"--phoneme-input",
action="store_true",
help="Flag to use pure phonemes as input"
)
#
parser.add_argument("-s", "--speaker", type=int, help="Id of speaker (default: 0)")
parser.add_argument(
Expand Down Expand Up @@ -107,6 +113,7 @@ def main() -> None:
# Load voice
voice = PiperVoice.load(args.model, config_path=args.config, use_cuda=args.cuda)
synthesize_args = {
"phoneme_input": args.phoneme_input,
"speaker_id": args.speaker,
"length_scale": args.length_scale,
"noise_scale": args.noise_scale,
Expand Down
9 changes: 7 additions & 2 deletions src/python_run/piper/voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def synthesize(
self,
text: str,
wav_file: wave.Wave_write,
phoneme_input: bool,
speaker_id: Optional[int] = None,
length_scale: Optional[float] = None,
noise_scale: Optional[float] = None,
Expand All @@ -103,6 +104,7 @@ def synthesize(

for audio_bytes in self.synthesize_stream_raw(
text,
phoneme_input=phoneme_input,
speaker_id=speaker_id,
length_scale=length_scale,
noise_scale=noise_scale,
Expand All @@ -114,15 +116,18 @@ def synthesize(
def synthesize_stream_raw(
self,
text: str,
phoneme_input: bool,
speaker_id: Optional[int] = None,
length_scale: Optional[float] = None,
noise_scale: Optional[float] = None,
noise_w: Optional[float] = None,
sentence_silence: float = 0.0,
) -> Iterable[bytes]:
"""Synthesize raw audio per sentence from text."""
sentence_phonemes = self.phonemize(text)

if phoneme_input:
sentence_phonemes = [list(text)]
else:
sentence_phonemes = self.phonemize(text)
# 16-bit mono
num_silence_samples = int(sentence_silence * self.config.sample_rate)
silence_bytes = bytes(num_silence_samples * 2)
Expand Down