js android tts,JS调用微软TTS DEMO朗读
// Create the Sapi SpVoice objectvar VoiceObj = new ActiveXObject("Sapi.SpVoice");// ChangeVoice() function://This function sets the newly selected voice choice from the Voice//Select box ...
// Create the Sapi SpVoice object
var VoiceObj = new ActiveXObject("Sapi.SpVoice");
// ChangeVoice() function:
// This function sets the newly selected voice choice from the Voice
// Select box on the Voice object.
function ChangeVoice() {
var i = parseInt(idsVoices.value);
VoiceObj.Voice = VoiceObj.GetVoices().Item(i);
}
// ChangeAudioOutput() function:
// This function sets the newly selected audio output choice from the
// Audio Output Select box on the Voice object.
function ChangeAudioOutput() {
var i = parseInt(idsAudioOutputs.value);
VoiceObj.AudioOutput = VoiceObj.GetAudioOutputs().Item(i);
}
// IncRate() function:
// This function increases the speaking rate by 1 up to a maximum
// of 10.
function IncRate() {
if(VoiceObj.Rate < 10) {
VoiceObj.Rate = VoiceObj.Rate + 1;
}
}
// DecRate() function:
// This function decreases the speaking rate by -1 down to a minimum
// of -10.
function DecRate() {
if(VoiceObj.Rate > -10) {
VoiceObj.Rate = VoiceObj.Rate - 1;
}
}
// IncVol() function:
// This function increases the speaking volume by 10 up to a maximum
// of 100.
function IncVol() {
if(VoiceObj.Volume < 200) {
VoiceObj.Volume = VoiceObj.Volume + 10;
}
}
// DecVol() function:
// This function decreases the speaking volume by -10 down to a minimum
// of 0.
function DecVol() {
if(VoiceObj.Volume > 9) {
VoiceObj.Volume = VoiceObj.Volume - 10;
}
}
// SpeakText() function:
// This function gets the text from the textbox and sends it to the
// Voice object's Speak() function. The value "1" for the second
// parameter corresponds to the SVSFlagsAsync value in the SpeechVoiceSpeakFlags
// enumerated type.
function SpeakText() {
if(idbSpeakText.value == "SpeakText") {
// Speak the string in the edit box
try {
VoiceObj.Speak(idTextBox.value, 2);
}
catch(exception) {
alert("Speak error");
}
}
else if(idbSpeakText.value == "Stop") {
// Speak empty string to Stop current speaking. The value "2" for
// the second parameter corresponds to the SVSFPurgeBeforeSpeak
// value in the SpeechVoiceSpeakFlags enumerated type.
VoiceObj.Speak("", 2);
}
}
更多推荐


所有评论(0)