-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend.py
More file actions
36 lines (22 loc) · 756 Bytes
/
Copy pathbackend.py
File metadata and controls
36 lines (22 loc) · 756 Bytes
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
from scipy.io import wavfile
import numpy as np
def get_audio(location):
''' Returns mono audio numpy array with samplerate'''
samplerate, data = wavfile.read(location)
if len(data.shape) == 1:
return samplerate, data
return samplerate, data.sum(axis=1)/data.shape[0]
def power_spectrum(array):
return (np.abs(array) ** 2)
def furiour(array):
return np.fft.rfft(array)
def get_cutoff_value(min, slope, p):
return min + slope * p
def get_last_non_zero_index(array):
threshold = max(array)/100
for i in reversed(range(len(array))):
if array[i] > threshold:
return i+1
return 0
def export(filename, rate, data):
wavfile.write(filename, rate, np.array(data, dtype="uint8"))