h5 develops voice broadcast function

1. Use the api that comes with windows, but most mobile browsers do not support it, and the compatibility is poor (not recommended)

1. Use the speechSynthesis attribute of the window, as shown in 1.1 as follows

                                                                        Figure 1.1

 2. The broadcast method speak() and the cancel broadcast method cancel() are mainly used, and then the initial entry to the page broadcasts once at a fixed time. If you enter the broadcast page and do not stay for too long, you can use the timer to cancel it directly. The entire code is shown in Figure 2.1

                                                                               Figure 2.1

2. Using the api that comes with uniapp, the compatibility almost covers most mobile browsers (recommended)

1. Use the createInnerAudioContext() method of uniap to create a voice instance, add the autoplay attribute and the voice playback link src to the instance, for details, please refer to uni.createInnerAudioContext() | uni-app official website

The core complete code is shown in the figure below:

Guess you like

Origin blog.csdn.net/weixin_44191318/article/details/129065707