コード例 #1
0
        public AITalkResultCode VoiceClear()
        {
            AITalkResultCode code = AITalkAPI.VoiceClear();

            this.OnWriteLog("[AITalkAPI_VoiceClear] " + code);
            return(code);
        }
コード例 #2
0
        protected override int MyAITalkProcTextBuf(AITalkEventReasonCode reasonCode, int jobID, IntPtr userData)
        {
            uint   size = 0;
            uint   pos  = 0;
            string kana = "";

            if ((reasonCode == AITalkEventReasonCode.AITALKEVENT_TEXTBUF_FLUSH) || (reasonCode == AITalkEventReasonCode.AITALKEVENT_TEXTBUF_FULL))
            {
                AITalkResultCode errorCode = AITalkAPI.GetKana(jobID, this._jobInfo.KanaBuffer, (uint)this._jobInfo.KanaBuffer.Capacity, out size, out pos);
                base.OnWriteLog(string.Concat(new object[] { "[AITalkAPI_GetKana] ", errorCode, " : ", size }));
                if (errorCode != AITalkResultCode.AITALKERR_SUCCESS)
                {
                    this.InvokeUserEventHandler <ErrorEventArgs>(new EventInVoker <ErrorEventArgs>(this.OnErrorOccured), new ErrorEventArgs("GetKana", errorCode, ""));
                }
                kana = this._jobInfo.KanaBuffer.ToString();
                JobInfo.TextBlock textBlock = this._jobInfo.AddTextBlock((int)pos, kana);
                this._jobInfo.GrowTextProcessingProgress(textBlock);
                int textProcessingProgressPercentage = this._jobInfo.GetTextProcessingProgressPercentage();
                TextProcessingEventArgs e            = new TextProcessingEventArgs(textBlock.Pos, textBlock.Text, kana, textProcessingProgressPercentage);
                this.InvokeUserEventHandler <TextProcessingEventArgs>(new EventInVoker <TextProcessingEventArgs>(this.OnTextProcessingProgress), e);
            }
            else if (reasonCode == AITalkEventReasonCode.AITALKEVENT_TEXTBUF_CLOSE)
            {
                TextProcessingEventArgs args2 = new TextProcessingEventArgs(0, "", "", 100);
                this.InvokeUserEventHandler <TextProcessingEventArgs>(new EventInVoker <TextProcessingEventArgs>(this.OnTextProcessingComplete), args2);
                this._jobInfo.TextProcessingDone = true;
                base.OnWriteLog("[JobInfo] " + this._jobInfo.ToString());
            }
            base.OnWriteLog(string.Concat(new object[] { "Callback [AITalkProcTextBuf] ", jobID, " : ", reasonCode.ToString(), " : ", (int)userData, " : ", kana }));
            return(0);
        }
コード例 #3
0
        public AITalkResultCode VoiceLoad(string voiceName)
        {
            AITalkResultCode code = AITalkAPI.VoiceLoad(voiceName);

            this.OnWriteLog("[AITalkAPI_VoiceLoad] " + code);
            return(code);
        }
コード例 #4
0
        public AITalkResultCode BLoadWordDic()
        {
            AITalkResultCode code = AITalkAPI.BLoadWordDic();

            this.OnWriteLog("[AITalkAPI_BLoadWordDic] " + code);
            return(code);
        }
コード例 #5
0
 public ErrorEventArgs(string name, AITalkResultCode errorCode, string message = "")
 {
     this.Name      = name;
     this.Type      = AITalkUtilEx.ErrorType.AITalk;
     this.ErrorCode = (int)errorCode;
     this.Message   = message;
 }
コード例 #6
0
        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);
        }
コード例 #7
0
        public AITalkResultCode ReloadWordDic(string pathDic)
        {
            AITalkResultCode code = AITalkAPI.ReloadWordDic(pathDic);

            this.OnWriteLog("[AITalkAPI_ReloadWordDic] " + code);
            return(code);
        }
コード例 #8
0
        public AITalkResultCode LangLoad(string dirLang)
        {
            AITalkResultCode code = AITalkAPI.LangLoad(dirLang);

            this.OnWriteLog("[AITalkAPI_LangLoad] " + code);
            return(code);
        }
コード例 #9
0
        public AITalkResultCode LangClear()
        {
            AITalkResultCode code = AITalkAPI.LangClear();

            this.OnWriteLog("[AITalkAPI_LangClear] " + code);
            return(code);
        }
コード例 #10
0
        private BufferedWaveProvider Provide(string text)
        {
            int id;
            AITalk_TJobParam param = new AITalk_TJobParam();

            param.modeInOut = AITalkJobInOut.AITALKIOMODE_PLAIN_TO_WAVE;
            param.userData  = IntPtr.Zero;

            code = AITalkAPI.TextToSpeech(out id, ref param, text);
            if (code != AITalkResultCode.AITALKERR_SUCCESS)
            {
                throw new Exception("スピーチ実行に失敗");
            }

            var waveProvider = new BufferedWaveProvider(new WaveFormat(44100, 16, 1));

            byte[]  waveBuffer = new byte[config.waveBufferSize];
            short[] buffer     = new short[config.waveBufferSize / 2];
            do
            {
                uint count;
                code = AITalkAPI.GetData(id, buffer, (uint)config.waveBufferSize / 2, out count);
                Buffer.BlockCopy(buffer, 0, waveBuffer, 0, (int)count * 2);
                waveProvider.AddSamples(waveBuffer, 0, (int)count * 2);
            } while (code == AITalkResultCode.AITALKERR_SUCCESS);
            if (code != AITalkResultCode.AITALKERR_NOMORE_DATA)
            {
                throw new Exception("変換データ読み取りに失敗");
            }

            code = AITalkAPI.CloseSpeech(id);
            return(waveProvider);
        }
コード例 #11
0
        public static AITalkResultCode GetLicenseDate(out string date)
        {
            StringBuilder    bufDate = new StringBuilder(30);
            AITalkResultCode code    = LicenseDate(bufDate);

            date = bufDate.ToString();
            return(code);
        }
コード例 #12
0
        public AITalkResultCode End()
        {
            AITalkResultCode code = AITalkAPI.End();

            this.OnWriteLog("[AITalkAPI_End] " + code);
            this._busy    = false;
            this._playing = false;
            return(code);
        }
コード例 #13
0
        public static AITalkResultCode GetLicenseInfo(string key, out string str, int len = 0x400)
        {
            uint             num;
            StringBuilder    bufVal = new StringBuilder(len);
            AITalkResultCode code   = LicenseInfo(key, bufVal, (uint)len, out num);

            str = bufVal.ToString();
            return(code);
        }
コード例 #14
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);
        }
コード例 #15
0
        protected void DoJob()
        {
            AITalkResultCode errorCode = AITalkResultCode.AITALKERR_SUCCESS;
            AITalkStatusCode status    = AITalkStatusCode.AITALKSTAT_DONE;

Label_0005:
            Thread.Sleep(base.GetStatusInterval);
            errorCode = base.GetStatus(this._jobInfo.JobID, out status);
            if ((errorCode != AITalkResultCode.AITALKERR_SUCCESS) || (status == AITalkStatusCode.AITALKSTAT_WRONG_STATE))
            {
                this.InvokeUserEventHandler <ErrorEventArgs>(new EventInVoker <ErrorEventArgs>(this.OnErrorOccured), new ErrorEventArgs("GetStatus", errorCode, ""));
            }
            else if (!this._jobInfo.Aborted)
            {
                if (this._jobInfo.TextProcessingDone && (this._jobInfo.TextBlockList.Count == 0))
                {
                    if (base._playing)
                    {
                        AudioEventArgs e = new AudioEventArgs(0, "", "", 0L);
                        this.InvokeUserEventHandler <AudioEventArgs>(new EventInVoker <AudioEventArgs>(this.OnPlayComplete), e);
                        base._playing = false;
                    }
                }
                else if ((((this.SynthMode & AITalk.SynthMode.Play) != AITalk.SynthMode.Play) || base._playing) && (((this.SynthMode & AITalk.SynthMode.Play) == AITalk.SynthMode.Play) || (status != AITalkStatusCode.AITALKSTAT_DONE)))
                {
                    goto Label_0005;
                }
            }
            if ((this.SynthMode & AITalk.SynthMode.Synthesize) != AITalk.SynthMode.Synthesize)
            {
                AITalkResultCode code3 = AITalkAPI.CloseKana(this._jobInfo.JobID, 0);
                base.OnWriteLog("[AITalkAPI_CloseKana] " + code3);
                if (code3 != AITalkResultCode.AITALKERR_SUCCESS)
                {
                    this.InvokeUserEventHandler <ErrorEventArgs>(new EventInVoker <ErrorEventArgs>(this.OnErrorOccured), new ErrorEventArgs("CloseKana", code3, ""));
                }
            }
            else
            {
                AITalkResultCode code4 = AITalkAPI.CloseSpeech(this._jobInfo.JobID, 0);
                base.OnWriteLog("[AITalkAPI_CloseSpeech] " + code4);
                if (code4 != AITalkResultCode.AITALKERR_SUCCESS)
                {
                    this.InvokeUserEventHandler <ErrorEventArgs>(new EventInVoker <ErrorEventArgs>(this.OnErrorOccured), new ErrorEventArgs("CloseSpeech", code4, ""));
                }
            }
            if (base._playing)
            {
                base.StopAudio();
                base._playing = false;
            }
            this._jobInfo = null;
            base._busy    = false;
            this.InvokeUserEventHandler <EventArgs>(new EventInVoker <EventArgs>(this.OnJobComplete), new EventArgs());
        }
コード例 #16
0
        public AITalkResultCode VersionInfo(int verbose, out string str)
        {
            uint             num2;
            int              capacity = 0x400;
            StringBuilder    sjis     = new StringBuilder(capacity);
            AITalkResultCode code     = AITalkAPI.VersionInfo(verbose, sjis, (uint)capacity, out num2);

            this.OnWriteLog("[AITalkAPI_VersionInfo] " + code);
            str = sjis.ToString();
            return(code);
        }
コード例 #17
0
 public static string GetErrorMessage(AITalkResultCode key)
 {
     try
     {
         return(_messages[key]);
     }
     catch
     {
         return("");
     }
 }
コード例 #18
0
        public void SetTuning(Tuning tuning)
        {
            if (tuning.Pitch >= 0)
            {
                ttsParam.Speaker[0].pitch = Range(0.5f, 2f, tuning.Pitch);
            }
            if (tuning.Volume >= 0)
            {
                ttsParam.Speaker[0].volume = Range(0f, 5f, tuning.Volume);
            }
            if (tuning.Range >= 0)
            {
                ttsParam.Speaker[0].range = Range(0f, 2f, tuning.Range);
            }
            if (tuning.Speed >= 0)
            {
                ttsParam.Speaker[0].speed = Range(0.5f, 4f, tuning.Speed);
            }

            if (tuning.pause.Middle >= 0)
            {
                ttsParam.Speaker[0].pauseMiddle = Range(80, 500, tuning.pause.Middle);
            }
            if (tuning.pause.Long >= 0)
            {
                ttsParam.Speaker[0].pauseLong = Range(100, 2000, tuning.pause.Long);
            }
            if (tuning.pause.Sentence >= 0)
            {
                ttsParam.Speaker[0].pauseSentence = Range(0, 10000, tuning.pause.Sentence);
            }
            if (tuning.Style != null)
            {
                ttsParam.Speaker[0].styleRate = tuning.Style;
            }

            ttsParam.Speaker[0].pauseLong     = Math.Max(ttsParam.Speaker[0].pauseLong, ttsParam.Speaker[0].pauseMiddle);
            ttsParam.Speaker[0].pauseSentence = Math.Max(ttsParam.Speaker[0].pauseSentence, ttsParam.Speaker[0].pauseLong);

            IntPtr ptr = AITalkMarshal.TTtsParamToIntPtr(ref ttsParam);

            // Marshal.WriteInt32(ptr, 500);
            // TTtsParamToIntPtrメソッドは、先頭にサイズを書き込んである。(構造体の定義になってるから当たり前)

            code = AITalkAPI.SetParam(ptr);

            if (code != AITalkResultCode.AITALKERR_SUCCESS)
            {
                throw new Exception("パラメータ設定に失敗: ");
            }
        }
コード例 #19
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);
        }
コード例 #20
0
        public AITalkResultCode Init(AITalk_TConfig config)
        {
            AITalkResultCode code = AITalkAPI.Init(ref config);

            this.OnWriteLog("[AITalkAPI_Init] " + code);
            if (code == AITalkResultCode.AITALKERR_SUCCESS)
            {
                this._disposed = false;
            }
            this._voiceSamplesPerSec = config.hzVoiceDB;
            this._kanaBuf            = new StringBuilder(0x4000);
            this._waveBuf            = new short[config.hzVoiceDB * 4];
            return(code);
        }
コード例 #21
0
ファイル: AITalkAPI.cs プロジェクト: Zoltanar/IthVnrSharpLib
        public static AITalkResultCode GetJeitaControl(int jobID, string ctrl)
        {
            int num = 1;

            while (true)
            {
                AITalkResultCode code = _GetJeitaControl(jobID, ctrl);
                if ((code != AITalkResultCode.AITALKERR_WAIT_TIMEOUT) || (num >= MaxTries))
                {
                    return(code);
                }
                Thread.Sleep(SleepTime);
                num++;
            }
        }
コード例 #22
0
        protected virtual int MyAITalkProcTextBuf(AITalkEventReasonCode reasonCode, int jobID, IntPtr userData)
        {
            uint   size = 0;
            uint   pos  = 0;
            string str  = "";

            if ((reasonCode == AITalkEventReasonCode.AITALKEVENT_TEXTBUF_FLUSH) || (reasonCode == AITalkEventReasonCode.AITALKEVENT_TEXTBUF_FULL))
            {
                AITalkResultCode code = AITalkAPI.GetKana(jobID, this._kanaBuf, (uint)this._kanaBuf.Capacity, out size, out pos);
                this.OnWriteLog(string.Concat(new object[] { "[AITalkAPI_GetKana] ", code, " : ", size }));
                str = this._kanaBuf.ToString();
            }
            this.OnWriteLog(string.Concat(new object[] { "Callback [AITalkProcTextBuf] ", jobID, " : ", reasonCode.ToString(), " : ", (int)userData, " : ", str }));
            return(0);
        }
コード例 #23
0
ファイル: AITalkAPI.cs プロジェクト: Zoltanar/IthVnrSharpLib
        public static AITalkResultCode GetData(int jobID, short[] rawBuf, uint lenBuf, out uint size)
        {
            int num = 1;

            while (true)
            {
                AITalkResultCode code = _GetData(jobID, rawBuf, lenBuf, out size);
                if ((code != AITalkResultCode.AITALKERR_WAIT_TIMEOUT) || (num >= MaxTries))
                {
                    return(code);
                }
                Thread.Sleep(SleepTime);
                num++;
            }
        }
コード例 #24
0
ファイル: AITalkAPI.cs プロジェクト: Zoltanar/IthVnrSharpLib
        public static AITalkResultCode GetKana(int jobID, StringBuilder textBuf, uint lenBuf, out uint size, out uint pos)
        {
            int num = 1;

            while (true)
            {
                AITalkResultCode code = _GetKana(jobID, textBuf, lenBuf, out size, out pos);
                if ((code != AITalkResultCode.AITALKERR_WAIT_TIMEOUT) || (num >= MaxTries))
                {
                    return(code);
                }
                Thread.Sleep(SleepTime);
                num++;
            }
        }
コード例 #25
0
ファイル: AITalkAPI.cs プロジェクト: Zoltanar/IthVnrSharpLib
        public static AITalkResultCode End()
        {
            int num = 1;

            while (true)
            {
                AITalkResultCode code = _End();
                if ((code != AITalkResultCode.AITALKERR_WAIT_TIMEOUT) || (num >= MaxTries))
                {
                    return(code);
                }
                Thread.Sleep(SleepTime);
                num++;
            }
        }
コード例 #26
0
ファイル: AITalkAPI.cs プロジェクト: Zoltanar/IthVnrSharpLib
        public static AITalkResultCode CloseSpeech(int jobID, int useEvent = 0)
        {
            int num = 1;

            while (true)
            {
                AITalkResultCode code = _CloseSpeech(jobID, useEvent);
                if ((code != AITalkResultCode.AITALKERR_WAIT_TIMEOUT) || (num >= MaxTries))
                {
                    return(code);
                }
                Thread.Sleep(SleepTime);
                num++;
            }
        }
コード例 #27
0
ファイル: AITalkAPI.cs プロジェクト: Zoltanar/IthVnrSharpLib
        public static AITalkResultCode VoiceLoad(string voiceName)
        {
            int num = 1;

            while (true)
            {
                AITalkResultCode code = _VoiceLoad(voiceName);
                if ((code != AITalkResultCode.AITALKERR_WAIT_TIMEOUT) || (num >= MaxTries))
                {
                    return(code);
                }
                Thread.Sleep(SleepTime);
                num++;
            }
        }
コード例 #28
0
ファイル: AITalkAPI.cs プロジェクト: Zoltanar/IthVnrSharpLib
        public static AITalkResultCode VersionInfo(int verbose, StringBuilder sjis, uint len, out uint size)
        {
            int num = 1;

            while (true)
            {
                AITalkResultCode code = _VersionInfo(verbose, sjis, len, out size);
                if ((code != AITalkResultCode.AITALKERR_WAIT_TIMEOUT) || (num >= MaxTries))
                {
                    return(code);
                }
                Thread.Sleep(SleepTime);
                num++;
            }
        }
コード例 #29
0
ファイル: AITalkAPI.cs プロジェクト: Zoltanar/IthVnrSharpLib
        public static AITalkResultCode TextToSpeech(out int jobID, ref AITalk_TJobParam param, string text)
        {
            int num = 1;

            while (true)
            {
                AITalkResultCode code = _TextToSpeech(out jobID, ref param, text);
                if ((code != AITalkResultCode.AITALKERR_WAIT_TIMEOUT) || (num >= MaxTries))
                {
                    return(code);
                }
                Thread.Sleep(SleepTime);
                num++;
            }
        }
コード例 #30
0
ファイル: AITalkAPI.cs プロジェクト: Zoltanar/IthVnrSharpLib
        public static AITalkResultCode GetStatus(int jobID, out AITalkStatusCode status)
        {
            int num = 1;

            while (true)
            {
                AITalkResultCode code = _GetStatus(jobID, out status);
                if ((code != AITalkResultCode.AITALKERR_WAIT_TIMEOUT) || (num >= MaxTries))
                {
                    return(code);
                }
                Thread.Sleep(SleepTime);
                num++;
            }
        }