コード例 #1
0
        public AIAudioResultCode ResumeAudio()
        {
            AIAudioResultCode code = AIAudioAPI.Resume();

            this.OnWriteLog("[AIAudioAPI_Resume] " + code);
            return(code);
        }
コード例 #2
0
 public ErrorEventArgs(string name, AIAudioResultCode errorCode, string message = "")
 {
     this.Name      = name;
     this.Type      = AITalkUtilEx.ErrorType.AIAudio;
     this.ErrorCode = (int)errorCode;
     this.Message   = message;
 }
コード例 #3
0
        public AIAudioResultCode PauseAudio()
        {
            AIAudioResultCode code = AIAudioAPI.Suspend();

            this.OnWriteLog("[AIAudioAPI_Suspend] " + code);
            return(code);
        }
コード例 #4
0
        public AIAudioResultCode CloseAudio()
        {
            AIAudioResultCode code = AIAudioAPI.Close();

            this.OnWriteLog("[AIAudioAPI_Close] " + code);
            this._playing = false;
            return(code);
        }
コード例 #5
0
        public AIAudioResultCode StopAudio()
        {
            AIAudioResultCode code = AIAudioAPI.ClearData();

            this.OnWriteLog("[AIAudioAPI_ClearData] " + code);
            this._playing = false;
            return(code);
        }
コード例 #6
0
        public AIAudioResultCode SaveWave(string path, ref AIAudio_TWaveFormat format, short[] wave)
        {
            byte[] dst = new byte[wave.Length * 2];
            Buffer.BlockCopy(wave, 0, dst, 0, dst.Length);
            AIAudioResultCode code = AIAudioAPI.SaveWave(path, ref format, dst, (uint)dst.Length);

            this.OnWriteLog("[AIAudioAPI_SaveWave] " + code);
            return(code);
        }
コード例 #7
0
        public AIAudioResultCode OpenAudio(ref AIAudio_TConfig param)
        {
            AIAudio_TConfig config = param;

            config.procNotify = this._AIAudioProcNotify;
            AIAudioResultCode code = AIAudioAPI.Open(ref config);

            this.OnWriteLog("[AIAudioAPI_Open] " + code);
            return(code);
        }
コード例 #8
0
 public static string GetErrorMessage(AIAudioResultCode key)
 {
     try
     {
         return(_messages[key]);
     }
     catch
     {
         return("");
     }
 }
コード例 #9
0
 private void PushQueuedEvents()
 {
     while (this._jobInfo.AudioEventQueue.Count > 0)
     {
         AudioEventParam   param     = this._jobInfo.AudioEventQueue.Dequeue();
         AIAudioResultCode errorCode = base.PushEvent(param.Tick, param.ToIntPtr());
         if ((errorCode != AIAudioResultCode.AIAUDIOERR_SUCCESS) && (errorCode != AIAudioResultCode.AIAUDIOERR_NO_PLAYING))
         {
             this.InvokeUserEventHandler <ErrorEventArgs>(new EventInVoker <ErrorEventArgs>(this.OnErrorOccured), new ErrorEventArgs("PushEvent_PushQueuedEvents", errorCode, ""));
         }
     }
 }
コード例 #10
0
ファイル: AIAudioAPI.cs プロジェクト: Zoltanar/IthVnrSharpLib
        public static AIAudioResultCode Open(ref AIAudio_TConfig config)
        {
            int num = 1;

            while (true)
            {
                AIAudioResultCode code = _Open(ref config);
                if ((code != AIAudioResultCode.AIAUDIOERR_WAIT_TIMEOUT) || (num >= MaxTries))
                {
                    return(code);
                }
                Thread.Sleep(SleepTime);
                num++;
            }
        }
コード例 #11
0
ファイル: AIAudioAPI.cs プロジェクト: Zoltanar/IthVnrSharpLib
        public static AIAudioResultCode Close()
        {
            int num = 1;

            while (true)
            {
                AIAudioResultCode code = _Close();
                if ((code != AIAudioResultCode.AIAUDIOERR_WAIT_TIMEOUT) || (num >= MaxTries))
                {
                    return(code);
                }
                Thread.Sleep(SleepTime);
                num++;
            }
        }
コード例 #12
0
        public AIAudioResultCode PushEvent(ulong tick, IntPtr userData)
        {
            if (!this._playing)
            {
                return(AIAudioResultCode.AIAUDIOERR_NO_PLAYING);
            }
            AIAudioResultCode code = AIAudioAPI.PushEvent(tick, userData);

            this.OnWriteLog(string.Concat(new object[] { "[AIAudioAPI_PushEvent] ", code, " : ", tick }));
            if (code != AIAudioResultCode.AIAUDIOERR_SUCCESS)
            {
                this._playing = false;
            }
            return(code);
        }
コード例 #13
0
        public AIAudioResultCode PushData(short[] wave, int size, int stop)
        {
            if (!this._playing)
            {
                return(AIAudioResultCode.AIAUDIOERR_NO_PLAYING);
            }
            if (wave == null)
            {
                return(AIAudioResultCode.AIAUDIOERR_INVALID_ARGUMENT);
            }
            byte[] dst = new byte[size * 2];
            Buffer.BlockCopy(wave, 0, dst, 0, dst.Length);
            AIAudioResultCode code = AIAudioAPI.PushData(dst, (uint)dst.Length, stop);

            this.OnWriteLog(string.Concat(new object[] { "[AIAudioAPI_PushData] ", code, " : ", dst.Length }));
            if (code != AIAudioResultCode.AIAUDIOERR_SUCCESS)
            {
                this._playing = false;
            }
            return(code);
        }
コード例 #14
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);
        }
コード例 #15
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);
        }