| 111 | _read_flags = 'rb' |
| 112 | |
| 113 | def __init__(self, data=None, filename=None, url=None, embed=None, rate=None, autoplay=False, normalize=True, *, |
| 114 | element_id=None): |
| 115 | if filename is None and url is None and data is None: |
| 116 | raise ValueError("No audio data found. Expecting filename, url, or data.") |
| 117 | if embed is False and url is None: |
| 118 | raise ValueError("No url found. Expecting url when embed=False") |
| 119 | |
| 120 | if url is not None and embed is not True: |
| 121 | self.embed = False |
| 122 | else: |
| 123 | self.embed = True |
| 124 | self.autoplay = autoplay |
| 125 | self.element_id = element_id |
| 126 | super(Audio, self).__init__(data=data, url=url, filename=filename) |
| 127 | |
| 128 | if self.data is not None and not isinstance(self.data, bytes): |
| 129 | if rate is None: |
| 130 | raise ValueError("rate must be specified when data is a numpy array or list of audio samples.") |
| 131 | self.data = Audio._make_wav(data, rate, normalize) |
| 132 | |
| 133 | def reload(self): |
| 134 | """Reload the raw data from file or URL.""" |