Phonegap TTS Plugin Android not working

后端 未结 2 518
鱼传尺愫
鱼传尺愫 2021-02-04 19:12

I am using the TTS Plugin from https://github.com/domaemon/org.apache.cordova.plugin.tts But the plugin does not seem to work. It does not even initialize.

Installed the

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-04 19:35

    result == 2 or STARTED works only once. If you again call the function it may not return 2 or STARTED (happened with me). so better dont use that condition in success of startup.

    /*********tts.js*************/
    var tts = {
        say: function() {
    	alert("tts");
        },
        startup: function(successCallback, errorCallback) {
    	console.log("TTS-Startup");
            cordova.exec(successCallback, errorCallback, "TTS", "startup", []);
        },
        speed: function(speed, successCallback, errorCallback) {
        cordova.exec(successCallback, errorCallback, "TTS", "speed", [speed]);
        },
        speak: function(text, successCallback, errorCallback) {
        	cordova.exec(successCallback, errorCallback, "TTS", "speak", [text]);
        }
      };
    
    if(!window.plugins) {
        window.plugins = {};
    }
    
    if (!window.plugins.tts) {
        window.plugins.tts = tts;
    }
    /**********calling from your js  after device ready***************/
     function visitToString(){
      window.plugins.tts.startup(function(result){
    			window.plugins.tts.speed(50,function(){
    				console.log('speed success');
    			},function(err){
    				console.log('speed err'+JSON.stringify(err));
    			});  
    	    	 window.plugins.tts.speak(finalstr,function(){
    	    		 console.log('speech success');
    	    	 },function(err){
    	    		 console.log('speech err'+JSON.stringify(err));
    	    	 });  
    		    
    	}, fail);
      }

提交回复
热议问题