js文本到语音到android web视图文本到语音

wbgh16ku  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(220)

大家好,我一直在一个网站上工作,我正在使用javascript文本到语音api来播放一些文本,它对web浏览器非常有用,但现在该项目正在移植到android,文本到语音根本不起作用。android开发者正在使用android的web视图在应用程序中打开网站,以便从web移植到android,我使用了mobiledetect.net的移动检测库,因此我可以检测它是否是android。由于我可以检测到“if mobile”,我想知道,当它是mobile时,是否有一种方法可以将一些android代码放在onclick属性中,然后调用android的文本到语音api else js函数。
函数从div中获取纯文本,并将其传递给text-to-speech。我想知道使用android是否也会发生同样的情况,通过检测手机,我可以在onclick属性中放置一些android代码,而android会处理其余部分。
--下面是我的javascript文本到语音的代码--

//area_id == div id with text.... btn_id = id of the button which is being clicked
function textToAudio(area_id, btn_id){
    var amISpeaking = window.speechSynthesis.speaking;

    if(amISpeaking){
        var etext = $("#"+btn_id).html();

        if(etext == "Play"){
            window.speechSynthesis.resume();
            $("#"+btn_id).html("Pause");
        }else if(etext == "Pause"){
            window.speechSynthesis.pause();
            $("#"+btn_id).html("Play");
        };

        return false;
    }else{
        $("#"+btn_id).html("Pause");
    };

    /* playing souund */
    var msg = $("#"+area_id).html();
    msg = $.trim(msg);

    if(empty_check(msg) || (msg == NO_VAL)){ msg = "Either there is no text or something went wrong during processing."; };

    let speech = new SpeechSynthesisUtterance();
    speech.lang = "en-US";

    speech.text = msg;
    speech.volume = 1;
    speech.rate = 1;
    speech.pitch = 1;

    window.speechSynthesis.speak(speech);
};

有人有什么想法吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题