Spaces:
Running
Running
Luis
commited on
Commit
•
c0a2456
1
Parent(s):
c30c603
add mp4_to_mp3.py
Browse files- python/util/mp4_to_mp3.py +33 -0
- python/util/plt_util.py +2 -2
python/util/mp4_to_mp3.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from moviepy.editor import *
|
2 |
+
import sys
|
3 |
+
# print('argv[1]:' + str(sys.argv[1]))
|
4 |
+
import os
|
5 |
+
from pydub import AudioSegment
|
6 |
+
|
7 |
+
|
8 |
+
def mp4_to_mp3(mp4_uri):
|
9 |
+
# Load the mp4 file
|
10 |
+
video = VideoFileClip(mp4_uri)
|
11 |
+
|
12 |
+
# Extract audio from video
|
13 |
+
video.audio.write_audiofile(mp4_uri + ".mp3")
|
14 |
+
|
15 |
+
|
16 |
+
def audio_to_wav(wav_uri, out_sample_rate=16000):
|
17 |
+
src = wav_uri
|
18 |
+
dst = wav_uri + ".wav"
|
19 |
+
if os.path.exists(dst): os.remove(dst)
|
20 |
+
|
21 |
+
# convert wav to mp3
|
22 |
+
sound = AudioSegment.from_file(src)
|
23 |
+
sound = sound.set_frame_rate(out_sample_rate)
|
24 |
+
sound.export(dst, format="wav")
|
25 |
+
|
26 |
+
print(' audio_to_wav: ', str(dst))
|
27 |
+
return dst
|
28 |
+
|
29 |
+
sys.argv
|
30 |
+
if len(sys.argv) > 1:
|
31 |
+
res = mp4_to_mp3(sys.argv[1])
|
32 |
+
else:
|
33 |
+
print(' usage: python mp4_to_mp3.py /path/to/mp4_file ')
|
python/util/plt_util.py
CHANGED
@@ -44,7 +44,7 @@ def plt_mfcc(single_channel, sample_rate):
|
|
44 |
log_mel_spec = librosa.power_to_db(mel_spec)
|
45 |
plt.figure()
|
46 |
librosa.display.specshow(log_mel_spec, sr=sample_rate, x_axis='time', y_axis='mel')
|
47 |
-
plt.colorbar(format='%+2.0f dB') # 右边的色度条
|
48 |
plt.title('MFCC')
|
49 |
|
50 |
# plot to image
|
@@ -75,7 +75,7 @@ def plt_mfcc2(wav_pathname, sample_rate):
|
|
75 |
plt.title('mel power spectrogram')
|
76 |
|
77 |
# draw a color bar
|
78 |
-
plt.colorbar(format='%+02.0f dB')
|
79 |
|
80 |
# Make the figure layout compact
|
81 |
plt.tight_layout()
|
|
|
44 |
log_mel_spec = librosa.power_to_db(mel_spec)
|
45 |
plt.figure()
|
46 |
librosa.display.specshow(log_mel_spec, sr=sample_rate, x_axis='time', y_axis='mel')
|
47 |
+
# plt.colorbar(format='%+2.0f dB') # 右边的色度条
|
48 |
plt.title('MFCC')
|
49 |
|
50 |
# plot to image
|
|
|
75 |
plt.title('mel power spectrogram')
|
76 |
|
77 |
# draw a color bar
|
78 |
+
# plt.colorbar(format='%+02.0f dB')
|
79 |
|
80 |
# Make the figure layout compact
|
81 |
plt.tight_layout()
|