name:
src/python/fingerprinter/reader.py
-rw-r--r--
918
1import numpy as np
2from pydub import AudioSegment
3
4
5def read(filename):
6 audiofile = AudioSegment.from_file(filename)
7 # Setting to single channel, mono, so we don't have to process to signals which are likely to be very similar.
8 audiofile = audiofile.set_channels(1)
9 data = np.fromstring(audiofile._data, np.int16)
10 channels = []
11 for chn in xrange(audiofile.channels):
12 channels.append(data[chn::audiofile.channels])
13 fs = audiofile.frame_rate
14 return channels, fs
15
16def read_single(filename):
17 audiofile = AudioSegment.from_file(filename)
18 # Setting to single channel, mono, so we don't have to process to signals which are likely to be very similar.
19 audiofile = audiofile.set_channels(1)
20 data = np.fromstring(audiofile._data, np.int16)
21 channels = []
22 for chn in xrange(audiofile.channels):
23 channels.append(data[chn::audiofile.channels])
24 fs = audiofile.frame_rate
25 return channels[0], fs