-
I'm loading a sound file, that the notebook generates, like so: SAMPLES_FILE = "samples.bin"
data_unpacked = np.asarray(
[d[0] for d in struct.iter_unpack("<H", Path(SAMPLES_FILE).read_bytes())]
)
# The microphone that recorded the samples has a certain bit depth for each sample.
# Convert to signed 16bit samples.
_data_float = data_unpacked / 8192.0
soundwave = _data_float * np.iinfo(np.int16).max
SAMPLE_RATE = 32000
BYTES_PER_SAMPLE = 2
with wave.open(str(Path(SAMPLES_FILE).with_suffix(".wav")), "w") as f:
f.setnchannels(1)
f.setsampwidth(BYTES_PER_SAMPLE)
f.setframerate(SAMPLE_RATE)
f.writeframes(data_unpacked.astype(np.int16))
mo.vstack(
[
mo.md("Example sound file:"),
mo.audio(src="samples.wav"),
]
)
#with open(str(Path(SAMPLES_FILE).with_suffix(".wav")), "rb") as _p:
# mo.audio(src=_p) The notebook can access the samples.bin, but it fails to embed an audio player with samples.wav. If I change to the App view I see, in the inspect panel, that I have also tried the second approach, using file context. Also, doesn't work. It doesn't even show the audio player with that code, so I might be doing something wrong there. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
This sounds like a bug - I will create an issue and fix it this week. |
Beta Was this translation helpful? Give feedback.
-
This is now fixed. Here is a recipe. with open("audiofile.wav", "rb") as _f:
audio_player = mo.audio(src=_f)
audio_player |
Beta Was this translation helpful? Give feedback.
This is now fixed. Here is a recipe.