﻿
var audio = new Object();
audio.server = "http://imtranslator.com/sockets/tts.asp";
audio.queryStr = "";
audio.play = function(dirct){
    var VoiceTxt="";
    getTransType();
    if(dirct == 0){
        VoiceTxt = $("content").value;lang = from_language;
    }
    else if(dirct == 1){
        VoiceTxt = $("contentout").value;lang = to_language;
    }
    if(VoiceTxt == "" || VoiceTxt == inputHint || VoiceTxt == outputHint){setHint("没有输入内容。");return;}
    
	if(VoiceTxt && lang){
        var rdID = Math.round(Math.random() * 1000000);//get random
		switch(lang){
			case "zh-CN":case "zh-TW":
				audio.queryStr = "dir=zh&speed=0&B=1&ID=" + rdID + "&chr=MiaHead&vc=VW%20Lily&text=";
				break;
			case "fr":
				audio.queryStr = "dir=fr&speed=0&B=1&ID=" + rdID + "&chr=Jessi&vc=Florence&text=";
				break;
			case "de":
				audio.queryStr = "dir=de&speed=0&B=1&ID=" + rdID + "&chr=James&vc=Stefan&text=";
				break;
			case "it":
				audio.queryStr = "dir=it&speed=0&B=1&ID=" + rdID + "&chr=TonyHead&vc=Matteo&text=";
				break;
			case "ja":
				audio.queryStr = "dir=ja&speed=0&B=1&ID=" + rdID + "&chr=MiaHead&vc=VW%20Misaki&text=";
				break;
			case "ko":
				audio.queryStr = "dir=ko&speed=0&B=1&ID=" + rdID + "&chr=MiaHead&vc=VW%20Yumi&text=";
				break;
			case "pt":
				audio.queryStr = "dir=pt&speed=0&B=1&ID=" + rdID + "&chr=Jenny&vc=Gabriela&text=";
				break;
			case "ru":
				//audio.queryStr = "dir=ru&speed=0&B=1&ID=" + rdID + "&chr=VoyagerHead&vc=ScanSoft%20Katerina_Telecom&text=";
				audio.queryStr = "speed=0&url=F_TR&dir=ru&B=1&ID=602794083&chr=VoyagerHead&vc=Olga&text="
				break;
			case "es":
				audio.queryStr = "dir=es&speed=0&B=1&ID=" + rdID + "&chr=Jason&vc=Jorge&text=";
				break;
			default:
				audio.queryStr = "dir=en&speed=0&B=1&ID=" + rdID + "&chr=PeterHead&vc=VW%20Paul&text=";
				break;
		}
		$("tts_iframe").src = audio.server + "?" + audio.queryStr + encodeURIComponent(VoiceTxt);
	}
	setHint("如果不能发音，请检查选择语言和输入内容是否匹配，或者是服务器处于高负荷中。");
	recordInfo(lang,VoiceTxt);
}


function recordInfo(lg,title){
    if(title.length > 30){title = title.substr(0,30);}
  
    var AJAX=crtAJAX();
    if (AJAX==null) {
            //setHint("您的浏览器原因，不能翻译。");
            return false;
    }
    else{
        AJAX.onreadystatechange = function() {
          if (AJAX.readyState==4 || AJAX.readyState=="complete") {
            AJAX=null;//free
          }                               
        }
        AJAX.open("POST", "../svrLib/ttsHandler.ashx"   , true);
        AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        AJAX.send("l=" + lg + "&t=" + encodeURIComponent(title));
    }

}
