from moviepy.editor import AudioFileClip, VideoFileClip
from config import set_config

config_ = set_config()


def get_wav(video_path):
    """提取音频"""
    # 音频采样率设置为：2K
    video = VideoFileClip(video_path, audio_fps=8000)
    # Extract the audio from the video
    audio = video.audio
    # Save the extracted audio to a file
    audio_path = video_path.replace('.mp4', '.wav')
    audio.write_audiofile(audio_path)
    return audio_path


def get_audio_duration(audio_file_path):
    """获取音频时长，单位：ms"""
    audio_clip = AudioFileClip(audio_file_path)
    audio_length = audio_clip.duration
    return int(audio_length * 1000)
