protected virtual int MyAITalkProcRawBuf(AITalkEventReasonCode reasonCode, int jobID, ulong tick, IntPtr userData) { short[] wave = null; uint size = 0; if ((reasonCode == AITalkEventReasonCode.AITALKEVENT_RAWBUF_FLUSH) || (reasonCode == AITalkEventReasonCode.AITALKEVENT_RAWBUF_FULL)) { AITalkResultCode code = AITalkAPI.GetData(jobID, this._waveBuf, (uint)this._waveBuf.Length, out size); this.OnWriteLog(string.Concat(new object[] { "[AITalkAPI_GetData] ", code, " : ", size })); if ((code == AITalkResultCode.AITALKERR_SUCCESS) && (size > 0)) { wave = this._waveBuf; if (reasonCode == AITalkEventReasonCode.AITALKEVENT_RAWBUF_FLUSH) { this.PushEvent(tick, (IntPtr)2L); } this.PushData(wave, (int)size, 0); } } else if (reasonCode == AITalkEventReasonCode.AITALKEVENT_RAWBUF_CLOSE) { this.PushEvent(tick, (IntPtr)3L); this.PushData(new short[0], 0, 1); } this.OnWriteLog(string.Concat(new object[] { "Callback [AITalkProcRawBuf] ", jobID, " : ", reasonCode.ToString(), " : ", tick, " : ", (int)userData, " : ", (wave != null) ? ((size * 2)).ToString() : "NODATA" })); return(0); }
protected override int MyAITalkProcRawBuf(AITalkEventReasonCode reasonCode, int jobID, ulong tick, IntPtr userData) { uint size = 0; short[] wave = null; if ((reasonCode == AITalkEventReasonCode.AITALKEVENT_RAWBUF_FLUSH) || (reasonCode == AITalkEventReasonCode.AITALKEVENT_RAWBUF_FULL)) { AITalkResultCode errorCode = AITalkAPI.GetData(jobID, this._jobInfo.WaveBuffer, (uint)this._jobInfo.WaveBuffer.Length, out size); base.OnWriteLog(string.Concat(new object[] { "[AITalkAPI_GetData] ", errorCode, " : ", size })); if (errorCode != AITalkResultCode.AITALKERR_SUCCESS) { this.InvokeUserEventHandler <ErrorEventArgs>(new EventInVoker <ErrorEventArgs>(this.OnErrorOccured), new ErrorEventArgs("GetData", errorCode, "")); } if ((errorCode == AITalkResultCode.AITALKERR_SUCCESS) && (size > 0)) { wave = this._jobInfo.WaveBuffer; if (this._jobInfo.NextSentenceStartTick >= 0L) { JobInfo.TextBlock block = this._jobInfo.TextBlockList[this._jobInfo.CurrentIndex]; block.Tick = this._jobInfo.NextSentenceStartTick; if ((this.SynthMode & AITalk.SynthMode.Play) == AITalk.SynthMode.Play) { AIAudioResultCode code2 = base.PushEvent((ulong)block.Tick, new AudioEventParam(AudioEventCode.Sentence, block.Pos, block.Text, block.Kana, (ulong)block.Tick).ToIntPtr()); if ((code2 != AIAudioResultCode.AIAUDIOERR_SUCCESS) && (code2 != AIAudioResultCode.AIAUDIOERR_NO_PLAYING)) { this.InvokeUserEventHandler <ErrorEventArgs>(new EventInVoker <ErrorEventArgs>(this.OnErrorOccured), new ErrorEventArgs("PushEvent_Progress", code2, "")); } } this._jobInfo.NextSentenceStartTick = -1L; } this.PushQueuedEvents(); if ((this.SynthMode & AITalk.SynthMode.Play) == AITalk.SynthMode.Play) { AIAudioResultCode code3 = base.PushData(wave, (int)size, 0); if ((code3 != AIAudioResultCode.AIAUDIOERR_SUCCESS) && (code3 != AIAudioResultCode.AIAUDIOERR_NO_PLAYING)) { this.InvokeUserEventHandler <ErrorEventArgs>(new EventInVoker <ErrorEventArgs>(this.OnErrorOccured), new ErrorEventArgs("PushData_Progress", code3, "")); } } } if ((reasonCode == AITalkEventReasonCode.AITALKEVENT_RAWBUF_FLUSH) && ((this.SynthMode & AITalk.SynthMode.TextProcess) == AITalk.SynthMode.TextProcess)) { this._jobInfo.GrowSynthesizingProgress(this._jobInfo.TextBlockList[this._jobInfo.CurrentIndex]); this._jobInfo.NextSentenceStartTick = (long)tick; this._jobInfo.CurrentIndex++; } int progress = ((this.SynthMode & AITalk.SynthMode.TextProcess) == AITalk.SynthMode.TextProcess) ? this._jobInfo.GetSynthesizeingProgressPercentage() : 0; SynthesizingEventArgs e = new SynthesizingEventArgs(tick, wave, (int)size, reasonCode == AITalkEventReasonCode.AITALKEVENT_RAWBUF_FLUSH, progress); this.InvokeUserEventHandler <SynthesizingEventArgs>(new EventInVoker <SynthesizingEventArgs>(this.OnSynthesizingProgress), e); } else { if ((this.SynthMode & AITalk.SynthMode.Play) == AITalk.SynthMode.Play) { AIAudioResultCode code4 = base.PushEvent(tick, new AudioEventParam(AudioEventCode.Complete, 0, "", "", tick).ToIntPtr()); if (code4 == AIAudioResultCode.AIAUDIOERR_SUCCESS) { code4 = base.PushData(new short[1], 1, 1); if ((code4 != AIAudioResultCode.AIAUDIOERR_SUCCESS) && (code4 != AIAudioResultCode.AIAUDIOERR_NO_PLAYING)) { this.InvokeUserEventHandler <ErrorEventArgs>(new EventInVoker <ErrorEventArgs>(this.OnErrorOccured), new ErrorEventArgs("PushData_Complete", code4, "")); } } else if (code4 != AIAudioResultCode.AIAUDIOERR_NO_PLAYING) { this.InvokeUserEventHandler <ErrorEventArgs>(new EventInVoker <ErrorEventArgs>(this.OnErrorOccured), new ErrorEventArgs("PushEvent_Complete", code4, "")); } } SynthesizingEventArgs args2 = new SynthesizingEventArgs(tick, null, 0, false, 100); this.InvokeUserEventHandler <SynthesizingEventArgs>(new EventInVoker <SynthesizingEventArgs>(this.OnSynthesizingComplete), args2); this._jobInfo.SynthesizingDone = true; } base.OnWriteLog(string.Concat(new object[] { "Callback [AITalkProcRawBuf] ", jobID, " : ", reasonCode.ToString(), " : ", tick, " : ", (int)userData, " : ", (wave != null) ? ((size * 2)).ToString() : "NODATA" })); return(0); }
public AITalkResultCode SynthSync(ref AITalk_TJobParam jobparam, string text, out string kana, out short[] wave) { int num; AITalkStatusCode code3; kana = null; wave = null; if (this._busy) { return(AITalkResultCode.AITALKERR_TOO_MANY_JOBS); } this._busy = true; AITalk_TTtsParam param = new AITalk_TTtsParam(); AITalkResultCode status = this.GetParam(ref param); this.OnWriteLog("[AITalkAPI_GetParam] " + status); if (status != AITalkResultCode.AITALKERR_SUCCESS) { this._busy = false; return(status); } param.procTextBuf = null; param.procRawBuf = null; param.procEventTts = null; status = this.SetParam(ref param); this.OnWriteLog("[AITalkAPI_SetParam] " + status); if (status != AITalkResultCode.AITALKERR_SUCCESS) { this._busy = false; return(status); } if ((jobparam.modeInOut == AITalkJobInOut.AITALKIOMODE_PLAIN_TO_AIKANA) || (jobparam.modeInOut == AITalkJobInOut.AITALKIOMODE_AIKANA_TO_JEITA)) { status = AITalkAPI.TextToKana(out num, ref jobparam, text); this.OnWriteLog(string.Concat(new object[] { "[AITalkAPI_TextToKana] ", status, " : ", num })); } else { status = AITalkAPI.TextToSpeech(out num, ref jobparam, text); this.OnWriteLog(string.Concat(new object[] { "[AITalkAPI_TextToSpeech] ", status, " : ", num })); } if (status != AITalkResultCode.AITALKERR_SUCCESS) { this._busy = false; return(status); } StringBuilder textBuf = new StringBuilder((int)param.lenTextBufBytes); short[] rawBuf = new short[param.lenRawBufBytes / 2]; List <short[]> list = new List <short[]>(); AITalkResultCode code2 = AITalkResultCode.AITALKERR_SUCCESS; Label_0166: Thread.Sleep(this.GetStatusInterval); status = AITalkAPI.GetStatus(num, out code3); if (status != AITalkResultCode.AITALKERR_SUCCESS) { code2 = status; } else { switch (code3) { case AITalkStatusCode.AITALKSTAT_WRONG_STATE: code2 = status; goto Label_02F4; case AITalkStatusCode.AITALKSTAT_INPROGRESS: goto Label_0166; } uint size = 0; uint num3 = 0; if (((jobparam.modeInOut == AITalkJobInOut.AITALKIOMODE_PLAIN_TO_WAVE) || (jobparam.modeInOut == AITalkJobInOut.AITALKIOMODE_PLAIN_TO_AIKANA)) || (jobparam.modeInOut == AITalkJobInOut.AITALKIOMODE_AIKANA_TO_JEITA)) { uint num4; status = AITalkAPI.GetKana(num, textBuf, (uint)textBuf.Capacity, out size, out num4); this.OnWriteLog(string.Concat(new object[] { "[AITalkAPI_GetKana] ", status, " : ", size })); if ((status != AITalkResultCode.AITALKERR_NOMORE_DATA) && (status != AITalkResultCode.AITALKERR_SUCCESS)) { code2 = status; goto Label_02F4; } if (size > 0) { if (kana == null) { kana = textBuf.ToString(); } else { kana = kana + textBuf.ToString(); } } } if (((jobparam.modeInOut == AITalkJobInOut.AITALKIOMODE_PLAIN_TO_WAVE) || (jobparam.modeInOut == AITalkJobInOut.AITALKIOMODE_AIKANA_TO_WAVE)) || (jobparam.modeInOut == AITalkJobInOut.AITALKIOMODE_JEITA_TO_WAVE)) { status = AITalkAPI.GetData(num, rawBuf, (uint)rawBuf.Length, out num3); this.OnWriteLog(string.Concat(new object[] { "[AITalkAPI_GetData] ", status, " : ", num3 })); if (status == AITalkResultCode.AITALKERR_NOMORE_DATA) { goto Label_02F4; } if (status != AITalkResultCode.AITALKERR_SUCCESS) { code2 = status; goto Label_02F4; } short[] dst = new short[num3]; Buffer.BlockCopy(rawBuf, 0, dst, 0, (int)(num3 * 2)); list.Add(dst); } if (((code3 != AITalkStatusCode.AITALKSTAT_DONE) || (size != 0)) || (num3 != 0)) { goto Label_0166; } } Label_02F4: if ((jobparam.modeInOut == AITalkJobInOut.AITALKIOMODE_PLAIN_TO_AIKANA) || (jobparam.modeInOut == AITalkJobInOut.AITALKIOMODE_AIKANA_TO_JEITA)) { status = AITalkAPI.CloseKana(num, 0); this.OnWriteLog("[AITalkAPI_CloseKana] " + status); } else { status = AITalkAPI.CloseSpeech(num, 0); this.OnWriteLog("[AITalkAPI_CloseSpeech] " + status); } if (list.Count > 0) { int num5 = 0; foreach (short[] numArray3 in list) { num5 += numArray3.Length; } wave = new short[num5]; int dstOffset = 0; foreach (short[] numArray4 in list) { Buffer.BlockCopy(numArray4, 0, wave, dstOffset, numArray4.Length * 2); dstOffset += numArray4.Length * 2; } } this._busy = false; if (code2 == AITalkResultCode.AITALKERR_SUCCESS) { return(status); } return(code2); }