File size: 429 Bytes
9310327
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import moviepy
import os
import glob
import moviepy.editor 

def extract_audio(vid_filename):
    video = moviepy.editor.VideoFileClip(vid_filename)
    duration = video.duration

    audio = video.audio
    wav_file_name = ""
    if audio is not None:
        wav_file_name = vid_filename.replace('.mp4', '.wav')  # Replace .mkv with .wav
        audio.write_audiofile(wav_file_name)

    return audio, wav_file_name, duration