Show More
@@ -103,8 +103,13 b' class Audio(DisplayObject):' | |||||
103 | import struct |
|
103 | import struct | |
104 | from io import BytesIO |
|
104 | from io import BytesIO | |
105 | import wave |
|
105 | import wave | |
106 | maxabsvalue = float(max(map(abs,data))) |
|
106 | try: | |
107 | scaled = map(lambda x: int(x/maxabsvalue*32767), data) |
|
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 | fp = BytesIO() |
|
113 | fp = BytesIO() | |
109 | waveobj = wave.open(fp,mode='wb') |
|
114 | waveobj = wave.open(fp,mode='wb') | |
110 | waveobj.setnchannels(1) |
|
115 | waveobj.setnchannels(1) |
General Comments 0
You need to be logged in to leave comments.
Login now