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