Show More
@@ -97,7 +97,6 b' class Audio(DisplayObject):' | |||||
97 | else: |
|
97 | else: | |
98 | self.mimetype = "audio/wav" |
|
98 | self.mimetype = "audio/wav" | |
99 |
|
|
99 | ||
100 |
|
||||
101 | def _make_wav(self,data,rate): |
|
100 | def _make_wav(self, data, rate): | |
102 | """ Transform a numpy array to a PCM bytestring """ |
|
101 | """ Transform a numpy array to a PCM bytestring """ | |
103 | import struct |
|
102 | import struct | |
@@ -105,13 +104,13 b' class Audio(DisplayObject):' | |||||
105 | import wave |
|
104 | import wave | |
106 | try: |
|
105 | try: | |
107 | import numpy as np |
|
106 | import numpy as np | |
|
107 | data = np.array(data,dtype=float) | |||
108 | if len(data.shape) > 1: |
|
108 | if len(data.shape) > 1: | |
109 | raise ValueError("encoding of stereo PCM signals are unsupported") |
|
109 | raise ValueError("encoding of stereo PCM signals are unsupported") | |
110 | data = np.array(data,dtype=float) |
|
110 | scaled = np.int16(data/np.max(np.abs(data))*32767).tolist() | |
111 | scaled = list(np.int16(data/np.max(np.abs(data))*32767)) |
|
|||
112 | except ImportError: |
|
111 | except ImportError: | |
113 | maxabsvalue = float(max(map(abs,data))) |
|
112 | print("Numpy is required to encode PCM from an array") | |
114 | scaled = map(lambda x: int(x/maxabsvalue*32767), data) |
|
113 | raise | |
115 | fp = BytesIO() |
|
114 | fp = BytesIO() | |
116 | waveobj = wave.open(fp,mode='wb') |
|
115 | waveobj = wave.open(fp,mode='wb') | |
117 | waveobj.setnchannels(1) |
|
116 | waveobj.setnchannels(1) |
General Comments 0
You need to be logged in to leave comments.
Login now