Troubleshooting the problem that the web page speech synthesis API has no effect

Introduction to Web Speech Synthesis API


h5 provides speech synthesis APIs, including SpeechSynthesis and SpeechSynthesisUtterance. For specific usage methods, please refer to Speech Synthesis (TTS) application scheme 123_Chengjiang's blog-CSDN blog , now mdn says that this is an experimental function , but as can be seen from the compatibility list, except for opera and Android webview on the mobile side, the support is very friendly.



Scenario 1. The operating system does not support the tts function


Although the compatibility of the api mentioned above is very friendly, it does not mean that it can run smoothly, because this api also depends on the system's reading engine, and some ghost or simplified windows systems may delete it.
The solution is to install it back, search and download [tts repair patch], and install it according to the steps of the corresponding download program. like

win7 system tts voice engine repair patch | tts voice engine repair patch win7 official latest version download_current software park_software download

(The patch of this link is not always effective after testing multiple win7)


To judge whether the system has this function, you can see [ Control Panel-Ease of Access-Ease of Access Center-Use a computer without a monitor ] and try it out in the " Set up text-to-language conversion " operation. If it does not support it, there will be the following prompt




Scenario 2. The api is executed but there is no sound


Execute the play method, but there is no sound. The problem is located because the voice package of the system is not selected correctly.
SpeechSynthesisUtterance has two attributes to set the speech package. The first one is to set the language through lang, for example, set it to 'zh-CN'. According to the applications installed in the system, there may be multiple language packages under the same lang, and the system will A voice package that meets this condition will be automatically matched, and this is where the problem arises. If the voice package matched by the system is from a third party, it may not be used in web page speech synthesis. This is also the cause of the problems encountered online. As shown below,



Call the getVoices method and you can see that there are two zh-CNs, and the first one with the default value of true is installed by a third-party software. If it matches this, it cannot be played.
The second way to set the voice package is to directly set SpeechSynthesisUtterance.voice, and the assignment is the object obtained by getVoices above. Here, set the name to "Microsoft Simmplified Chinese". Note that the name may be different in different browsers. For example, in the chrome browser, it is "Google Mandarin (Mainland China)".


The properties of localService and default do not seem to be trustworthy. The final solution is to find the installed third-party application and delete it. If the application cannot be deleted, it seems that the name can be used for self-matching, or manual selection can be provided directly. way is more reliable.
How to add voice to computer see

Appendix A: Supported Languages ​​and Voices

Guess you like

Origin blog.csdn.net/cscj2010/article/details/126838934