Luis commited on
Commit
2f2cd12
·
1 Parent(s): 9314ba2
Files changed (2) hide show
  1. miaow_16k.mp3 +0 -0
  2. test_mp3.py +51 -0
miaow_16k.mp3 ADDED
Binary file (20.6 kB). View file
 
test_mp3.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # https://tfhub.dev/google/lite-model/yamnet/classification/tflite/1
3
+
4
+ import tensorflow as tf
5
+ import tensorflow_hub as hub
6
+ import numpy as np
7
+ import csv
8
+
9
+ # import matplotlib.pyplot as plt
10
+ # from IPython.display import Audio
11
+ from scipy.io import wavfile
12
+ import scipy
13
+
14
+ # import soundfile as sf
15
+ # import audio2numpy as a2n
16
+ import os
17
+
18
+ import gradio as gr
19
+
20
+ # import audio2numpy
21
+ # import numpy as np
22
+
23
+ from pydub import AudioSegment
24
+ from matplotlib import pyplot as plt
25
+
26
+
27
+ # https://stackoverflow.com/questions/16634128/how-to-extract-the-raw-data-from-a-mp3-file-using-python
28
+ # This will open and read the audio file with pydub. Replace the file path with
29
+ # your own file.
30
+ audio_file = AudioSegment.from_file('miaow_16k.mp3')
31
+
32
+ # Set up a list for us to dump PCM samples into, and create a 'data' variable
33
+ # so we don't need to type audio_file._data again
34
+ data = audio_file._data
35
+ pcm16_signed_integers = []
36
+
37
+ # This loop decodes the bytestring into PCM samples.
38
+ # The bytestring is a stream of little-endian encoded signed integers.
39
+ # This basically just cuts each two-byte sample out of the bytestring, converts
40
+ # it to an integer, and appends it to the list of samples.
41
+ for sample_index in range(len(data) // 2):
42
+ sample = int.from_bytes(data[sample_index * 2:sample_index * 2 + 2], 'little', signed=True)
43
+ pcm16_signed_integers.append(sample / 255)
44
+
45
+ wav_data = np.array([x for x in pcm16_signed_integers])
46
+ sample_rate = 16000
47
+ if debug: print(f'pcm16_signed_integers: {len(pcm16_signed_integers)}')
48
+
49
+ # Now plot the samples!
50
+ plt.plot(pcm16_signed_integers)
51
+ plt.show()