-
Notifications
You must be signed in to change notification settings - Fork 0
/
m4a_to_wav.py
executable file
·50 lines (36 loc) · 1.41 KB
/
m4a_to_wav.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Packages reqd: pydub, ffmpeg
# pydub - pip install pydub
# ffmpeg:
# sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next
# sudo apt-get update
# sudo apt-get install ffmpeg
## Load the m4a files (in M4a_files.tar.gz)
#!tar -xvzf M4a_files.tar.gz
## Delete unwanted files (here: Tapping files)
#!find M4a_files/ -name 'tapping_results.*' -delete
## Converting to wav
# Using pydub
# Convert m4a extension files to wav extension files
import os
import argparse
from pydub import AudioSegment
formats_to_convert = ['.m4a']
for (dirpath, dirnames, filenames) in os.walk("/"):
for filename in filenames:
if filename.endswith(tuple(formats_to_convert)):
filepath = dirpath + '/' + filename
(path, file_extension) = os.path.splitext(filepath)
file_extension_final = file_extension.replace('.', '')
try:
track = AudioSegment.from_file(filepath,
file_extension_final)
wav_filename = filename.replace(file_extension_final, 'wav')
wav_path = dirpath + '/' + wav_filename
print('CONVERTING: ' + str(filepath))
file_handle = track.export(wav_path, format='wav')
os.remove(filepath)
except:
print("ERROR CONVERTING " + str(filepath))
# Rename folder M4a_files as wav_files
#!mv M4a_files wav_files
#@dylankolson