Show More
@@ -17,9 +17,10 b' class Audio(DisplayObject):' | |||||
17 |
|
17 | |||
18 | Parameters |
|
18 | Parameters | |
19 | ---------- |
|
19 | ---------- | |
20 | data : numpy array, unicode, str or bytes |
|
20 | data : numpy array, list, unicode, str or bytes | |
21 | Can be a |
|
21 | Can be a | |
22 |
* Numpy 1d array containing the desired waveform (mono) |
|
22 | * Numpy 1d array containing the desired waveform (mono) | |
|
23 | * List of float or integer representing the waveform (mono) | |||
23 | * String containing the filename |
|
24 | * String containing the filename | |
24 | * Bytestring containing raw PCM data or |
|
25 | * Bytestring containing raw PCM data or | |
25 | * URL pointing to a file on the web. |
|
26 | * URL pointing to a file on the web. | |
@@ -109,8 +110,8 b' class Audio(DisplayObject):' | |||||
109 | raise ValueError("encoding of stereo PCM signals are unsupported") |
|
110 | raise ValueError("encoding of stereo PCM signals are unsupported") | |
110 | scaled = np.int16(data/np.max(np.abs(data))*32767).tolist() |
|
111 | scaled = np.int16(data/np.max(np.abs(data))*32767).tolist() | |
111 | except ImportError: |
|
112 | except ImportError: | |
112 | print("Numpy is required to encode PCM from an array") |
|
113 | maxabsvalue = float(max([abs(x) for x in data])) | |
113 | raise |
|
114 | scaled = [int(x/maxabsvalue*32767) for x in data] | |
114 | fp = BytesIO() |
|
115 | fp = BytesIO() | |
115 | waveobj = wave.open(fp,mode='wb') |
|
116 | waveobj = wave.open(fp,mode='wb') | |
116 | waveobj.setnchannels(1) |
|
117 | waveobj.setnchannels(1) |
General Comments 0
You need to be logged in to leave comments.
Login now