Spaces:
Running
Running
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
import argparse | |
import os | |
from ffmpy import FFmpeg | |
from project_settings import project_path | |
def get_args(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
"--filename", | |
default=(project_path / "data/voice_clone_audio/e2_tts/audio_0_3_clone_from_audio_0_2.wav").as_posix(), | |
type=str, | |
) | |
parser.add_argument( | |
"--output_file", | |
default="temp.wav", | |
type=str, | |
) | |
parser.add_argument("--change_by_radio", default=0.5, type=float) | |
args = parser.parse_args() | |
return args | |
def change_by_ratio(audio_path: str, output_file: str, ratio): | |
ext = os.path.basename(audio_path).strip().split(".")[-1] | |
if ext not in ["wav", "mp3"]: | |
raise Exception("format error") | |
if os.path.exists(output_file): | |
os.remove(output_file) | |
ff = FFmpeg( | |
inputs={audio_path: None}, | |
outputs={output_file: f'-filter:a "volume={ratio}"'} | |
) | |
ff.run() | |
return output_file | |
def main(): | |
args = get_args() | |
output_file = change_by_ratio( | |
args.filename, | |
args.output_file, | |
args.change_by_radio, | |
) | |
print(f"output_file: {output_file}") | |
return | |
if __name__ == "__main__": | |
main() | |