mirror of
https://github.com/correl/dejavu.git
synced 2024-11-27 11:09:51 +00:00
Added the fix for issue #13 in the original repository.
This commit is contained in:
parent
7122e110d1
commit
8a7358d426
1 changed files with 14 additions and 1 deletions
|
@ -15,9 +15,22 @@ def find_files(path, extensions):
|
||||||
yield (p, extension)
|
yield (p, extension)
|
||||||
|
|
||||||
|
|
||||||
def read(filename):
|
def read(filename, limit=None):
|
||||||
|
"""
|
||||||
|
Reads any file supported by pydub (ffmpeg) and returns the data contained
|
||||||
|
within.
|
||||||
|
|
||||||
|
Can be optionally limited to a certain amount of seconds from the start
|
||||||
|
of the file by specifying the `limit` parameter. This is the amount of
|
||||||
|
seconds from the start of the file.
|
||||||
|
|
||||||
|
returns: (samplerate, channels)
|
||||||
|
"""
|
||||||
audiofile = AudioSegment.from_file(filename)
|
audiofile = AudioSegment.from_file(filename)
|
||||||
|
|
||||||
|
if limit:
|
||||||
|
audiofile = audiofile[:limit * 1000]
|
||||||
|
|
||||||
data = np.fromstring(audiofile._data, np.int16)
|
data = np.fromstring(audiofile._data, np.int16)
|
||||||
|
|
||||||
channels = []
|
channels = []
|
||||||
|
|
Loading…
Reference in a new issue