Open microbit-matt-hillsdon opened 9 months ago
CC @microbit-robert
Since #111 (unreleased, available on staging) we now handle the error and just skip playing rather than leaving the sim in a bad state. Still interested in persuing a sample rate change.
Coincidentally (I assume!), modspeech has a mode=3 option that doubles the sample rate. That mode works in Safari 13. There’s also some code for linear interpolation but not sure it happens with mode=3 or whether it's needed for an OK result.
I've just tested mode=3
and fixed a small bug related to it (now pushed to master micropython-microbit-v2). I think it would be fine to use this mode, it sounds similar enough to the default mode=1
.
There's also a mode=4
which is a linearly interpolated version of mode=3
. You can also try this mode 4, it may be better (or worse!) on a PC's speaker.
So far as I can tell we can only trigger mode=3 by passing an undocumented mode keyword argument from user code.
Yes, that's correct.
I guess you would like to have the default mode compile-time configurable?
I guess you would like to have the default mode compile-time configurable?
@dpgeorge yes, I think it would make sense for the simulator build to define the mode.
OK, I've now pushed a commit to the micropython-microbit-v2
repository which allows setting the default mode. You can add this line to the simulator's mpconfigport.h
file:
#define MICROPY_PY_SPEECH_DEFAULT_MODE (3)
OK, I've now pushed a commit to the
micropython-microbit-v2
repository which allows setting the default mode. You can add this line to the simulator'smpconfigport.h
file:#define MICROPY_PY_SPEECH_DEFAULT_MODE (3)
Thanks, confirmed this works in Safari 13. I'll close this issue when the simulator changes are merged.
On #109 we fixed audio for older Safari by using the prefixed APIs and older style of node/buffer creation.
It didn't fix speech because modspeech uses a 19000 sample rate but old Safari has a lower bound of 22050 (contrary to the spec but it was early days).
Coincidentally (I assume!), modspeech has a mode=3 option that doubles the sample rate. That mode works in Safari 13. There’s also some code for linear interpolation but not sure it happens with mode=3 or whether it's needed for an OK result.
So far as I can tell we can only trigger mode=3 by passing an undocumented mode keyword argument from user code.
@dpgeorge what is the mode used for? Do you think we could use this or something similar to get a >= 22050 sample rate in the simulator? We could consider doing this just for older Safari if we felt it would impact the output. We could detect the need to do this in the speech hal init function or any point after a user interaction with the simulator.
Alternatively we could look at resampling in JavaScript between modspeech and Web Audio. The older Web Audio API has no support for this so we'd be doing it ourselves.