Пример #1
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("パラメータ設定に失敗: ");
            }
        }
Пример #2
0
        private void InitializeTuning()
        {
            int paramPtrSize;

            paramPtr = AITalkMarshal.AllocateTTtsParam(1, out paramPtrSize);
            Marshal.WriteInt32(paramPtr, paramPtrSize);

            uint sz;

            code = AITalkAPI.GetParam(paramPtr, out sz);
            if (code != AITalkResultCode.AITALKERR_SUCCESS)
            {
                throw new Exception("パラメータ取得に失敗: ");
            }
            ttsParam = AITalkMarshal.IntPtrToTTtsParam(paramPtr);
            if (ttsParam.voiceName != currentSpeaker)
            {
                throw new Exception("パラメータ取得結果がなんかおかしい");
            }

            return;
        }