mirror of
https://github.com/suno-ai/bark.git
synced 2026-01-09 13:57:57 -05:00
[Eng] Add command line interface (#314)
This commit is contained in:
committed by
GitHub
parent
2d9eded792
commit
19636b21b8
@@ -158,7 +158,10 @@ By default, `generate_audio` works well with around 13 seconds of spoken text. F
|
||||
</details>
|
||||
|
||||
|
||||
|
||||
## Command line
|
||||
```commandline
|
||||
python -m bark --text "Hello, my name is Suno." --output_filename "example.wav"
|
||||
```
|
||||
|
||||
## 💻 Installation
|
||||
*‼️ CAUTION ‼️ Do NOT use `pip install bark`. It installs a different package, which is not managed by Suno.*
|
||||
|
||||
3
bark/__main__.py
Normal file
3
bark/__main__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .cli import cli
|
||||
|
||||
cli()
|
||||
71
bark/cli.py
Normal file
71
bark/cli.py
Normal file
@@ -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}")
|
||||
Reference in New Issue
Block a user