예제 #1
0
        public virtual AITalkResultCode SynthAsync(ref AITalk_TJobParam jobparam, string text)
        {
            int jobID;

            if (this._busy || this._playing)
            {
                return(AITalkResultCode.AITALKERR_TOO_MANY_JOBS);
            }
            this._busy    = true;
            this._playing = true;
            AITalk_TTtsParam param = new AITalk_TTtsParam();
            AITalkResultCode res   = this.GetParam(ref param);

            this.OnWriteLog("[AITalkAPI_GetParam] " + res);
            if (res != AITalkResultCode.AITALKERR_SUCCESS)
            {
                this._busy    = false;
                this._playing = false;
                return(res);
            }
            param.procTextBuf  = this._AITalkProcTextBuf;
            param.procRawBuf   = this._AITalkProcRawBuf;
            param.procEventTts = this._AITalkProcEventTTS;
            res = this.SetParam(ref param);
            this.OnWriteLog("[AITalkAPI_SetParam] " + res);
            if (res != AITalkResultCode.AITALKERR_SUCCESS)
            {
                this._busy    = false;
                this._playing = false;
                return(res);
            }
            this.OnWriteLog("[AIAuidoAPI_ClearData] " + AIAudioAPI.ClearData());
            res = AITalkAPI.TextToSpeech(out jobID, ref jobparam, text);
            this.OnWriteLog("[AITalkAPI_TextToSpeech] " + res);
            if (res != AITalkResultCode.AITALKERR_SUCCESS)
            {
                this._busy    = false;
                this._playing = false;
                return(res);
            }
            new Thread(delegate {
                AITalkStatusCode code;
                do
                {
                    Thread.Sleep(this.GetStatusInterval);
                    res = this.GetStatus(jobID, out code);
                }while ((this._playing && (res == AITalkResultCode.AITALKERR_SUCCESS)) && (code != AITalkStatusCode.AITALKSTAT_DONE));
                AITalkAPI.CloseSpeech(jobID, 0);
                this.OnWriteLog("[AITalkAPI_CloseSpeech] " + res);
                this._busy = false;
            })
            {
                IsBackground = true
            }.Start();
            return(res);
        }
예제 #2
0
        public AITalkResultCode SetParam(ref AITalk_TTtsParam param)
        {
            IntPtr           pParam = AITalkMarshal.TTtsParamToIntPtr(ref param);
            AITalkResultCode code   = AITalkAPI.SetParam(pParam);

            this.OnWriteLog("[AITalkAPI_SetParam] " + code);
            Marshal.FreeCoTaskMem(pParam);
            if (code == AITalkResultCode.AITALKERR_SUCCESS)
            {
                this._kanaBuf = new StringBuilder((int)param.lenTextBufBytes);
                this._waveBuf = new short[param.lenRawBufBytes / 2];
            }
            return(code);
        }
예제 #3
0
        public AITalkResultCode GetParam(ref AITalk_TTtsParam param)
        {
            uint             num;
            AITalkResultCode code = AITalkAPI.GetParam(IntPtr.Zero, out num);

            this.OnWriteLog("[AITalkAPI_GetParam] " + code);
            if (code == AITalkResultCode.AITALKERR_INSUFFICIENT)
            {
                IntPtr ptr = Marshal.AllocCoTaskMem((int)num);
                Marshal.WriteInt32(ptr, (int)num);
                code = AITalkAPI.GetParam(ptr, out num);
                this.OnWriteLog("[AITalkAPI_GetParam] " + code);
                if (code != AITalkResultCode.AITALKERR_SUCCESS)
                {
                    Marshal.FreeCoTaskMem(ptr);
                    return(code);
                }
                param = AITalkMarshal.IntPtrToTTtsParam(ptr);
                Marshal.FreeCoTaskMem(ptr);
            }
            return(code);
        }
예제 #4
0
        public static AITalk_TTtsParam IntPtrToTTtsParam(IntPtr pParam)
        {
            AITalk_TTtsParam param = new AITalk_TTtsParam();
            int ofs = 0;

            param.size                = ReadUInt32(pParam, ref ofs);
            param.procTextBuf         = (AITalkProcTextBuf)ReadDelegate(pParam, ref ofs, typeof(AITalkProcTextBuf));
            param.procRawBuf          = (AITalkProcRawBuf)ReadDelegate(pParam, ref ofs, typeof(AITalkProcRawBuf));
            param.procEventTts        = (AITalkProcEventTTS)ReadDelegate(pParam, ref ofs, typeof(AITalkProcEventTTS));
            param.lenTextBufBytes     = ReadUInt32(pParam, ref ofs);
            param.lenRawBufBytes      = ReadUInt32(pParam, ref ofs);
            param.volume              = ReadSingle(pParam, ref ofs);
            param.pauseBegin          = ReadInt32(pParam, ref ofs);
            param.pauseTerm           = ReadInt32(pParam, ref ofs);
            param.voiceName           = ReadString(pParam, ref ofs, 80);
            param.Jeita.femaleName    = ReadString(pParam, ref ofs, 80);
            param.Jeita.maleName      = ReadString(pParam, ref ofs, 80);
            param.Jeita.pauseMiddle   = ReadInt32(pParam, ref ofs);
            param.Jeita.pauseLong     = ReadInt32(pParam, ref ofs);
            param.Jeita.pauseSentence = ReadInt32(pParam, ref ofs);
            param.Jeita.control       = ReadString(pParam, ref ofs, 12);
            param.numSpeakers         = ReadUInt32(pParam, ref ofs);
            param.__reserved__        = ReadInt32(pParam, ref ofs);
            param.Speaker             = new AITalk_TTtsParam.TSpeakerParam[param.numSpeakers];
            for (int i = 0; i < param.numSpeakers; i++)
            {
                param.Speaker[i].voiceName     = ReadString(pParam, ref ofs, 80);
                param.Speaker[i].volume        = ReadSingle(pParam, ref ofs);
                param.Speaker[i].speed         = ReadSingle(pParam, ref ofs);
                param.Speaker[i].pitch         = ReadSingle(pParam, ref ofs);
                param.Speaker[i].range         = ReadSingle(pParam, ref ofs);
                param.Speaker[i].pauseMiddle   = ReadInt32(pParam, ref ofs);
                param.Speaker[i].pauseLong     = ReadInt32(pParam, ref ofs);
                param.Speaker[i].pauseSentence = ReadInt32(pParam, ref ofs);
            }
            return(param);
        }
예제 #5
0
        public static IntPtr TTtsParamToIntPtr(ref AITalk_TTtsParam param)
        {
            int    num;
            IntPtr ptr = AllocateTTtsParam((int)param.numSpeakers, out num);
            int    ofs = 0;

            WriteUInt32(ptr, ref ofs, param.size);
            WriteDelegate(ptr, ref ofs, param.procTextBuf);
            WriteDelegate(ptr, ref ofs, param.procRawBuf);
            WriteDelegate(ptr, ref ofs, param.procEventTts);
            WriteUInt32(ptr, ref ofs, param.lenTextBufBytes);
            WriteUInt32(ptr, ref ofs, param.lenRawBufBytes);
            WriteSingle(ptr, ref ofs, param.volume);
            WriteInt32(ptr, ref ofs, param.pauseBegin);
            WriteInt32(ptr, ref ofs, param.pauseTerm);
            WriteString(ptr, ref ofs, param.voiceName, 80);
            WriteString(ptr, ref ofs, param.Jeita.femaleName, 80);
            WriteString(ptr, ref ofs, param.Jeita.maleName, 80);
            WriteInt32(ptr, ref ofs, param.Jeita.pauseMiddle);
            WriteInt32(ptr, ref ofs, param.Jeita.pauseLong);
            WriteInt32(ptr, ref ofs, param.Jeita.pauseSentence);
            WriteString(ptr, ref ofs, param.Jeita.control, 12);
            WriteUInt32(ptr, ref ofs, param.numSpeakers);
            WriteInt32(ptr, ref ofs, param.__reserved__);
            for (int i = 0; i < param.numSpeakers; i++)
            {
                WriteString(ptr, ref ofs, param.Speaker[i].voiceName, 80);
                WriteSingle(ptr, ref ofs, param.Speaker[i].volume);
                WriteSingle(ptr, ref ofs, param.Speaker[i].speed);
                WriteSingle(ptr, ref ofs, param.Speaker[i].pitch);
                WriteSingle(ptr, ref ofs, param.Speaker[i].range);
                WriteInt32(ptr, ref ofs, param.Speaker[i].pauseMiddle);
                WriteInt32(ptr, ref ofs, param.Speaker[i].pauseLong);
                WriteInt32(ptr, ref ofs, param.Speaker[i].pauseSentence);
            }
            return(ptr);
        }
예제 #6
0
        public AITalkResultCode Do(AITalk.SynthMode synthMode, string text, AITalk.SynthOption synthOption)
        {
            AITalk_TJobParam param2;

            if (base._busy || base._playing)
            {
                return(AITalkResultCode.AITALKERR_TOO_MANY_JOBS);
            }
            this.SynthMode   = synthMode;
            this.SynthOption = synthOption;
            base._busy       = true;
            int jobID              = -1;
            AITalkResultCode code  = AITalkResultCode.AITALKERR_SUCCESS;
            AITalk_TTtsParam param = new AITalk_TTtsParam();

            code = base.GetParam(ref param);
            base.OnWriteLog("[AITalkAPI_GetParam] " + code);
            if (code != AITalkResultCode.AITALKERR_SUCCESS)
            {
                base._busy = false;
                return(code);
            }
            param.pauseBegin   = ((synthOption & AITalk.SynthOption.UseBeginPause) == AITalk.SynthOption.UseBeginPause) ? this._beginPause : 0;
            param.pauseTerm    = ((synthOption & AITalk.SynthOption.UseTermPause) == AITalk.SynthOption.UseTermPause) ? this._termPause : 0;
            param.procTextBuf  = base._AITalkProcTextBuf;
            param.procRawBuf   = base._AITalkProcRawBuf;
            param.procEventTts = base._AITalkProcEventTTS;
            code = base.SetParam(ref param);
            base.OnWriteLog("[AITalkAPI_SetParam] " + code);
            if (code != AITalkResultCode.AITALKERR_SUCCESS)
            {
                base._busy = false;
                return(code);
            }
            if ((this.SynthMode & AITalk.SynthMode.TextProcess) == AITalk.SynthMode.TextProcess)
            {
                this._jobInfo = new JobInfo(this.SynthMode, text, this.SynthOption, param.lenTextBufBytes, param.lenRawBufBytes);
            }
            else
            {
                this._jobInfo = new JobInfo(this.SynthMode, text, this.SynthOption, param.lenTextBufBytes, param.lenRawBufBytes);
                this._jobInfo.TextBlockList.Add(new JobInfo.TextBlock(0, text, text, "", 1f, 1f, 1f, 1f));
            }
            param2.userData = IntPtr.Zero;
            if (this.SynthMode == AITalk.SynthMode.TextProcess)
            {
                param2.modeInOut = AITalkJobInOut.AITALKIOMODE_PLAIN_TO_AIKANA;
            }
            else if ((this.SynthMode == AITalk.SynthMode.Synthesize) || (this.SynthMode == AITalk.SynthMode.KanaToSpeech))
            {
                param2.modeInOut = AITalkJobInOut.AITALKIOMODE_AIKANA_TO_WAVE;
            }
            else if ((this.SynthMode == AITalk.SynthMode.TextToWave) || (this.SynthMode == AITalk.SynthMode.TextToSpeech))
            {
                param2.modeInOut = AITalkJobInOut.AITALKIOMODE_PLAIN_TO_WAVE;
            }
            else
            {
                base._busy = false;
                return(code);
            }
            if ((this.SynthMode & AITalk.SynthMode.Play) == AITalk.SynthMode.Play)
            {
                AIAudioResultCode errorCode = AIAudioAPI.ClearData();
                base.OnWriteLog("[AIAuidoAPI_ClearData] " + errorCode);
                if ((errorCode != AIAudioResultCode.AIAUDIOERR_SUCCESS) && (errorCode != AIAudioResultCode.AIAUDIOERR_NO_PLAYING))
                {
                    this.InvokeUserEventHandler <ErrorEventArgs>(new EventInVoker <ErrorEventArgs>(this.OnErrorOccured), new ErrorEventArgs("ClearData", errorCode, ""));
                    base._busy = false;
                    return(code);
                }
                base._playing = true;
            }
            if ((this.SynthMode & AITalk.SynthMode.Synthesize) != AITalk.SynthMode.Synthesize)
            {
                code = AITalkAPI.TextToKana(out jobID, ref param2, this._jobInfo.SynthText);
                base.OnWriteLog(string.Concat(new object[] { "[AITalkAPI_TextToKana] ", code, " : ", jobID }));
            }
            else
            {
                code = AITalkAPI.TextToSpeech(out jobID, ref param2, this._jobInfo.SynthText);
                base.OnWriteLog(string.Concat(new object[] { "[AITalkAPI_TextToSpeech] ", code, " : ", jobID }));
            }
            if (code != AITalkResultCode.AITALKERR_SUCCESS)
            {
                base._playing = false;
                base._busy    = false;
                return(code);
            }
            this._jobInfo.JobID = jobID;
            new Thread(new ThreadStart(this.DoJob))
            {
                IsBackground = true
            }.Start();
            return(code);
        }
예제 #7
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);
        }