Show More
@@ -4,11 +4,6 b' Authors : MinRK, gregcaporaso, dannystaple' | |||
|
4 | 4 | """ |
|
5 | 5 | from os.path import exists, isfile, splitext, abspath, join, isdir |
|
6 | 6 | from os import walk, sep |
|
7 | import base64 | |
|
8 | import struct | |
|
9 | from io import BytesIO | |
|
10 | import wave | |
|
11 | import mimetypes | |
|
12 | 7 | |
|
13 | 8 | from IPython.core.display import DisplayObject |
|
14 | 9 | |
@@ -25,7 +20,7 b' class Audio(DisplayObject):' | |||
|
25 | 20 | data : numpy array, unicode, str or bytes |
|
26 | 21 | Can be a |
|
27 | 22 | * Numpy array containing the desired waveform, |
|
28 |
* String containing |
|
|
23 | * String containing the filename | |
|
29 | 24 | * Bytestring containing raw PCM data or |
|
30 | 25 | * URL pointing to a file on the web. |
|
31 | 26 | |
@@ -91,6 +86,7 b' class Audio(DisplayObject):' | |||
|
91 | 86 | |
|
92 | 87 | def reload(self): |
|
93 | 88 | """Reload the raw data from file or URL.""" |
|
89 | import mimetypes | |
|
94 | 90 | if self.embed: |
|
95 | 91 | super(Audio, self).reload() |
|
96 | 92 | |
@@ -104,6 +100,9 b' class Audio(DisplayObject):' | |||
|
104 | 100 | |
|
105 | 101 | def _make_wav(self,data,rate): |
|
106 | 102 | """ Transform a numpy array to a PCM bytestring """ |
|
103 | import struct | |
|
104 | from io import BytesIO | |
|
105 | import wave | |
|
107 | 106 | maxabsvalue = max(map(abs,data)) |
|
108 | 107 | scaled = map(lambda x: int(x/maxabsvalue*32767), data) |
|
109 | 108 | fp = BytesIO() |
@@ -137,6 +136,7 b' class Audio(DisplayObject):' | |||
|
137 | 136 | return src.format(src=self.src_attr(),type=self.mimetype, autoplay=self.autoplay_attr()) |
|
138 | 137 | |
|
139 | 138 | def src_attr(self): |
|
139 | import base64 | |
|
140 | 140 | if self.embed and (self.data is not None): |
|
141 | 141 | return """data:{type};base64,{base64}""".format(type=self.mimetype, base64=base64.encodestring(self.data)) |
|
142 | 142 | elif self.url is not None: |
General Comments 0
You need to be logged in to leave comments.
Login now