Show More
@@ -103,8 +103,13 b' class Audio(DisplayObject):' | |||
|
103 | 103 | import struct |
|
104 | 104 | from io import BytesIO |
|
105 | 105 | import wave |
|
106 | maxabsvalue = float(max(map(abs,data))) | |
|
107 | scaled = map(lambda x: int(x/maxabsvalue*32767), data) | |
|
106 | try: | |
|
107 | import numpy as np | |
|
108 | data = np.array(data,dtype=float) | |
|
109 | scaled = list(np.int16(data/np.max(np.abs(data))*32767)) | |
|
110 | except ImportError: | |
|
111 | maxabsvalue = float(max(map(abs,data))) | |
|
112 | scaled = map(lambda x: int(x/maxabsvalue*32767), data) | |
|
108 | 113 | fp = BytesIO() |
|
109 | 114 | waveobj = wave.open(fp,mode='wb') |
|
110 | 115 | waveobj.setnchannels(1) |
General Comments 0
You need to be logged in to leave comments.
Login now