Skip to content

modspeech doesn't work on iPad Safari 13.x and 14.1 (works on 14.5) #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
microbit-matt-hillsdon opened this issue Feb 22, 2024 · 6 comments · May be fixed by #113
Open

modspeech doesn't work on iPad Safari 13.x and 14.1 (works on 14.5) #110

microbit-matt-hillsdon opened this issue Feb 22, 2024 · 6 comments · May be fixed by #113

Comments

@microbit-matt-hillsdon
Copy link
Contributor

microbit-matt-hillsdon commented Feb 22, 2024

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.

@microbit-matt-hillsdon
Copy link
Contributor Author

CC @microbit-robert

microbit-matt-hillsdon added a commit that referenced this issue Feb 23, 2024
…111)

- Workaround for #110 where we've observed that the sample rate of 19000 isn't supported. We'll aim to increase the sample rate in a separate PR but this will at least mean the simulator isn't put in a bad state.
- Reuse the audio context created after the user interaction, as there are limits to how many you can create on Safari 13 (4 in my BrowserStack testing). I think we always intended to do this, but careful review needed as this is a more significant change than I was anticipating. We already had clean up code for the nodes when the board stops. We never cleaned up the context. So I think we were assuming it lived forever. If this doesn't work out then an alternative is to try closing the old one before creating the new one.
@microbit-matt-hillsdon
Copy link
Contributor Author

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.

@dpgeorge
Copy link
Collaborator

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?

@microbit-matt-hillsdon
Copy link
Contributor Author

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.

@dpgeorge
Copy link
Collaborator

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)

microbit-matt-hillsdon added a commit that referenced this issue Mar 27, 2024
Needs testing but likely closes #110
@microbit-matt-hillsdon
Copy link
Contributor Author

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)

Thanks, confirmed this works in Safari 13. I'll close this issue when the simulator changes are merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants