def audio(dg, data, format="audio/wav", start_time=0): """Display an audio player. Parameters ---------- data : str, bytes, BytesIO, numpy.ndarray, or file opened with io.open(). Raw audio data, filename, or a URL pointing to the file to load. Numpy arrays and raw data formats must include all necessary file headers to match specified file format. start_time: int The time from which this element should start playing. format : str The mime type for the audio file. Defaults to 'audio/wav'. See https://tools.ietf.org/html/rfc4281 for more info. Example ------- >>> audio_file = open('myaudio.ogg', 'rb') >>> audio_bytes = audio_file.read() >>> >>> st.audio(audio_bytes, format='audio/ogg') .. output:: https://share.streamlit.io/0.25.0-2JkNY/index.html?id=Dv3M9sA7Cg8gwusgnVNTHb height: 400px """ audio_proto = AudioProto() coordinates = dg._get_coordinates() # type: ignore marshall_audio(coordinates, audio_proto, data, format, start_time) return dg._enqueue("audio", audio_proto) # type: ignore
def audio(self, data, format="audio/wav", start_time=0): """Display an audio player. Parameters ---------- data : str, bytes, BytesIO, numpy.ndarray, or file opened with io.open(). Raw audio data, filename, or a URL pointing to the file to load. Numpy arrays and raw data formats must include all necessary file headers to match specified file format. start_time: int The time from which this element should start playing. format : str The mime type for the audio file. Defaults to 'audio/wav'. See https://tools.ietf.org/html/rfc4281 for more info. Example ------- >>> audio_file = open('myaudio.ogg', 'rb') >>> audio_bytes = audio_file.read() >>> >>> st.audio(audio_bytes, format='audio/ogg') .. output:: https://share.streamlit.io/streamlit/docs/main/python/api-examples-source/charts.audio.py height: 465px """ audio_proto = AudioProto() coordinates = self.dg._get_delta_path_str() marshall_audio(coordinates, audio_proto, data, format, start_time) return self.dg._enqueue("audio", audio_proto)