HoneyTian's picture
first commit
a8c8d73
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
这调整的是播放速度, 会改变声音的频率.
"""
import argparse
import os.path
from pydub import AudioSegment
from pydub.playback import play
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("--speed", default=1.3, type=float)
args = parser.parse_args()
return args
def main():
args = get_args()
sound = AudioSegment.from_wav(args.filename)
altered_sound = sound._spawn(sound.raw_data, overrides={
"frame_rate": int(sound.frame_rate * args.speed)
})
altered_sound .set_frame_rate(sound.frame_rate)
# play(altered_sound)
if os.path.exists(args.output_file):
os.remove(args.output_file)
altered_sound.export(args.output_file, format="wav")
return
if __name__ == "__main__":
main()