To render image in HTML from numpy array, I can do
def numpy_to_b64(array):
im_pil = Image.fromarray(array)
buff = BytesIO()
im_pil.save(buff, format="png")
im_b64 = base64.b64encode(buff.getvalue()).decode("utf-8")
return im_b64
and use img
tag
array_b64 = numpy_to_b64(array)
html.Img(src='data:image/png;base64,{}'.format(array_b64))
I wonder if there is a similar approach for audio, or how can I convert a 1-D numpy array which represents audio waveform to a format that can be put in audio
tag?