
﻿
(function(win){var _recorders=[];function SpeechRecorderAdapter(option){var _this=this;var _id=option.id||"speech-recorder-adapter-"+new Date().getTime();for(var i=0;i<_recorders.length;i++){if(_id===_recorders[i].id){return _recorders[i];}}
_this.id=_id;_recorders.push(_this);var _events=option.events||{};var _proxy;_this.__proxy__=_proxy={};if(document.getElementById(_this.id)===null){var playerPanel=document.createElement("div");playerPanel.id=_this.id;document.body.appendChild(playerPanel);}
if(!win.SpeechRecorderSettings){LogUtil.error("Cannot find SpeechRecorder Settings...");return null;}
var swfUrl=option.speechRecorderUrl?option.speechRecorderUrl:SpeechRecorderSettings.Root+"SpeechRecorder.swf";if(SpeechRecorderSettings.IsDebug===true){swfUrl+="?r="+Math.random();}
var recordOptios={swf:swfUrl,width:option.width||"100%",height:option.height||"100%",expressInstall:SpeechRecorderSettings.Root+"expressInstall.swf",flashVars:{skin:SpeechRecorderSettings.Root+"Skins/sound.swf",recorderId:_this.id,enableWebLog:SpeechRecorderSettings.EnableWebLog,mspServer:SpeechRecorderSettings.MspServer,logLvl:SpeechRecorderSettings.LogLvl,mscLogLvl:SpeechRecorderSettings.MscLogLvl,plugins:SpeechRecorderSettings.Plugins}};var _recorder=new SpeechRecorder(_this.id,recordOptios);_recorder.addEventListener(SpeechRecorderEvent.READY,onReady);_recorder.addEventListener(SpeechRecorderEvent.ERROR,onError);_recorder.addEventListener(SpeechRecorderEvent.RECORD_STATE,onRecordState);_recorder.addEventListener(SpeechRecorderEvent.EVAL_RESULT,onEvalResult);_recorder.addEventListener(SpeechRecorderEvent.RECORDING,onRecording);_recorder.addEventListener(SpeechRecorderEvent.MICROPHONE_STATE,onMicrophoneState);_recorder.addEventListener(SpeechRecorderEvent.PLAYING,onPlaying);_recorder.addEventListener(SpeechRecorderEvent.PLAY_STATE,onPlayState);_recorder.addEventListener(SpeechRecorderEvent.AUDIO_LOADED,onAudioLoaded);_recorder.addEventListener(SpeechRecorderEvent.AUDIO_CHECK_RESULT,onAudioCheckResult);_recorder.addEventListener(SpeechRecorderEvent.PLUGIN_LOAD,onPluginLoad);_recorder.addEventListener(SpeechRecorderEvent.IAT_RESULT,onIATResult);_recorder.addEventListener(SpeechRecorderEvent.IAT_COMPLETE,onIATComplete);function onPlayState(e){LogUtil.debug("SpeechRecorderAdapter::onPlayState, oldstate:"+e.oldstate+", newstate:"+e.newstate);if(e.newstate==="PLAYING"&&e.oldstate!=="PLAYING"){_events.onPlayBegin&&_events.onPlayBegin.call(_this,e);}else if(e.newstate==="PAUSE"&&e.oldstate==="PLAYING"){_events.onPlayPause&&_events.onPlayPause.call(_this,e);}else if(e.newstate==="IDLE"&&e.oldstate!=="IDLE"){_events.onPlayStop&&_events.onPlayStop.call(_this,e);}}
function onReady(){_events.onReady&&_events.onReady.call(_this);}
function onError(e){LogUtil.error("{ ErrorType:"+e.errorType+", Msg:"+e.msg+", errorCode:"+e.errorCode+"}");_recorder.endEvaluate(true);var callback=_events.onError||_this.__events__.onError;if(callback){callback.call(_this,e);}};function onRecording(e){var callback=_events.onRecording||_this.__events__.onRecording;if(callback){callback.call(_this,e);}};function onRecordState(e){var callback;if(e===RecordStatus.Begin){callback=_events.onRecordBegin||_this.__events__.onRecordBegin;callback.call(_this);}
else if(e===RecordStatus.End){callback=_events.onRecordEnd||_this.__events__.onRecordEnd;callback.call(_this);}}
function onMicrophoneState(status){_events.onMicrophoneState&&_events.onMicrophoneState.call(_this,status);}
function onAudioLoaded(e){_events.onAudioLoaded&&_events.onAudioLoaded.call(_this,e);}
function onAudioCheckResult(e){_events.onAudioCheckResult&&_events.onAudioCheckResult.call(_this,e);}
function onIATResult(e){_events.onIATResult&&_events.onIATResult.call(_this,e);}
function onIATComplete(e){_events.onIATComplete&&_events.onIATComplete.call(_this,e);}
function onPlaying(e){_events.onPlaying&&_events.onPlaying.call(_this,e);}
function onEvalResult(e){switch(e.resultType){case EvalCallbackType.TRACKINFO:var callback=_events.onTrackInfo||_this.__events__.onTrackInfo;callback.call(_this,e.result);break;case EvalCallbackType.SCORE:default:callback=_events.onEvalResult||_this.__events__.onEvalResult;callback.call(_this,e);break;}}
function onPluginLoad(e){_events.onPluginLoad&&_events.onPluginLoad.call(_this,e);}
_proxy.record=function(recordOption){var callback=_events.onBeforeRecord||_this.__events__.onBeforeRecord;if(callback.call(_this,recordOption)!==false){return _recorder.beginEvaluate(recordOption);}
return false;};_proxy.stop=function(isForce){return _recorder.endEvaluate(isForce);};this.playRecordAudio=function(){_recorder.playRecordAudio();};this.showSecuritySettings=function(){_recorder.showSecuritySettings();};this.getMicrophoneStatus=function(){return _recorder.getMicrophoneStatus();};this.getMicrophoneGain=function(){return _recorder.getMicrophoneGain();};this.setMicrophoneGain=function(gain){_recorder.setMicrophoneGain(gain);};this.getFlashPlayerState=function(){return _recorder.getFlashPlayerState();};this.loadAudio=function(audioId,autoPlay){_recorder.loadAudio(audioId,autoPlay!==false);};this.play=function(){_recorder.playAudio();};this.playRange=function(begPos,endPos){_recorder.playRange(begPos,endPos);};this.pause=function(){_recorder.pauseAudio();};this.stopPlay=function(){_recorder.stopAudio();};this.getVolume=function(){return _recorder.getVolume();};this.setVolume=function(vol){_recorder.setVolume(vol);};this.setMute=function(isMute){_recorder.setMute(isMute);};this.showSkin=function(isShow){_recorder.showSkin(isShow);};this.audioCheck=function(audioTime){return _recorder.audioCheck(audioTime);};this.__class__.check.call(this);};SpeechRecorderAdapter.prototype=new SpeechJS.RecorderAdapterBase();SpeechRecorderAdapter.prototype.constructor=SpeechRecorderAdapter;win.SpeechRecorderAdapter=SpeechRecorderAdapter;})(window);