1234567891011121314151617181920 |
- import IPython.display
- import numpy as np
- import json
- from scipy.io.wavfile import write
- def Audio(audio: np.ndarray, rate: int, name: str):
- filename = f"output/{name}.wav"
- amplitude = np.iinfo(np.int16).max
- write(filename, rate, (audio*amplitude).astype(np.int16))
- return IPython.display.HTML(f"""
- <audio controls>
- <source src="{filename}" type="audio/wav">
- Your browser does not support the audio element.
- </audio>
- <br/>
- <a href="{filename}">{filename}</a>
- """)
|