forked from suno-ai/bark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Eng] Add command line interface (suno-ai#314)
- Loading branch information
1 parent
2d9eded
commit 19636b2
Showing
3 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .cli import cli | ||
|
||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import argparse | ||
from typing import Dict, Optional, Union | ||
import os | ||
|
||
from scipy.io.wavfile import write as write_wav | ||
from .api import generate_audio | ||
from .generation import SAMPLE_RATE | ||
|
||
|
||
def cli(): | ||
"""Commandline interface.""" | ||
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
parser.add_argument("--text", type=str, help="text to be turned into audio") | ||
parser.add_argument( | ||
"--output_filename", | ||
type=str, | ||
default="bark_generation.wav", | ||
help="output audio file name", | ||
) | ||
parser.add_argument("--output_dir", type=str, default=".", help="directory to save the outputs") | ||
parser.add_argument( | ||
"--history_prompt", | ||
type=Optional[Union[Dict, str]], | ||
default=None, | ||
help="history choice for audio cloning", | ||
) | ||
parser.add_argument( | ||
"--text_temp", | ||
default=0.7, | ||
type=float, | ||
help="generation temperature (1.0 more diverse, 0.0 more conservative)", | ||
) | ||
parser.add_argument( | ||
"--waveform_temp", | ||
default=0.7, | ||
type=float, | ||
help="generation temperature (1.0 more diverse, 0.0 more conservative)", | ||
) | ||
parser.add_argument("--silent", default=False, type=bool, help="disable progress bar") | ||
parser.add_argument( | ||
"--output_full", | ||
default=False, | ||
type=bool, | ||
help="return full generation to be used as a history prompt", | ||
) | ||
|
||
args = vars(parser.parse_args()) | ||
input_text: str = args.get("text") | ||
output_filename: str = args.get("output_filename") | ||
output_dir: str = args.get("output_dir") | ||
history_prompt: Optional[Union[Dict, str]] = args.get("history_prompt") | ||
text_temp: float = args.get("text_temp") | ||
waveform_temp: float = args.get("waveform_temp") | ||
silent: bool = args.get("silent") | ||
output_full: bool = args.get("output_full") | ||
|
||
try: | ||
os.makedirs(output_dir, exist_ok=True) | ||
generated_audio = generate_audio( | ||
input_text, | ||
history_prompt=history_prompt, | ||
text_temp=text_temp, | ||
waveform_temp=waveform_temp, | ||
silent=silent, | ||
output_full=output_full, | ||
) | ||
output_file_path = os.path.join(output_dir, output_filename) | ||
write_wav(output_file_path, SAMPLE_RATE, generated_audio) | ||
print(f"Done! Output audio file is saved at: '{output_file_path}'") | ||
except Exception as e: | ||
print(f"Oops, an error occurred: {e}") |