| 95 | _read_flags = 'rb' |
| 96 | |
| 97 | def __init__(self, data=None, filename=None, url=None, embed=None, rate=None, autoplay=False, normalize=True, *, |
| 98 | element_id=None): |
| 99 | if filename is None and url is None and data is None: |
| 100 | raise ValueError("No audio data found. Expecting filename, url, or data.") |
| 101 | if embed is False and url is None: |
| 102 | raise ValueError("No url found. Expecting url when embed=False") |
| 103 | |
| 104 | if url is not None and embed is not True: |
| 105 | self.embed = False |
| 106 | else: |
| 107 | self.embed = True |
| 108 | self.autoplay = autoplay |
| 109 | self.element_id = element_id |
| 110 | super(Audio, self).__init__(data=data, url=url, filename=filename) |
| 111 | |
| 112 | if self.data is not None and not isinstance(self.data, bytes): |
| 113 | if rate is None: |
| 114 | raise ValueError("rate must be specified when data is a numpy array or list of audio samples.") |
| 115 | self.data = Audio._make_wav(data, rate, normalize) |
| 116 | |
| 117 | def reload(self): |
| 118 | """Reload the raw data from file or URL.""" |