Skip to content

Add --seconds option to generate.py #284

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

Open
wants to merge 3 commits 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
14 changes: 12 additions & 2 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from wavenet import WaveNetModel, mu_law_decode, mu_law_encode, audio_reader

SAMPLES = 16000
SAMPLES_PER_SECOND = 16000
TEMPERATURE = 1.0
LOGDIR = './logdir'
WAVENET_PARAMS = './wavenet_params.json'
Expand All @@ -38,11 +39,19 @@ def _ensure_positive_float(f):
parser = argparse.ArgumentParser(description='WaveNet generation script')
parser.add_argument(
'checkpoint', type=str, help='Which model checkpoint to generate from')
parser.add_argument(
'--seconds',
type=_ensure_positive_float,
default=None,
help='How many seconds of audio to generate. '
'Each second is equivalent to 16000 samples. '
'Overrides --samples.')
parser.add_argument(
'--samples',
type=int,
default=SAMPLES,
help='How many waveform samples to generate')
help='How many waveform samples to generate. '
'Will be ignored if --seconds is also provided.')
parser.add_argument(
'--temperature',
type=_ensure_positive_float,
Expand Down Expand Up @@ -106,7 +115,8 @@ def _ensure_positive_float(f):
raise ValueError("Globally conditioning, but global condition was "
"not specified. Use --gc_id to specify global "
"condition.")

if arguments.seconds:
arguments.samples = int(arguments.seconds * SAMPLES_PER_SECOND)
return arguments


Expand Down