예제 #1
0
        public void Speak(string text)
        {
            //不定長情報のメモリー確保
            IntPtr     aqtk_p     = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(AQTK_VOICE)));
            AQTK_VOICE aqtk_voice = (AQTK_VOICE)Marshal.PtrToStructure(aqtk_p, typeof(AQTK_VOICE));

            aqtk_voice.Init();

            //文字読み込み
            System.Text.Encoding utf8Enc = System.Text.Encoding.GetEncoding("UTF-8");

            byte[] koeUtfBytes = utf8Enc.GetBytes(text);

            int    size   = 0;
            IntPtr wavPtr = AquesTalk_Synthe_Utf8(ref aqtk_voice, koeUtfBytes, ref size);

            if (wavPtr == IntPtr.Zero)
            {
            }

            //C#であつかえるように
            byte[] wav_data = new byte[size];
            Marshal.Copy(wavPtr, wav_data, 0, size);

            //解放
            AquesTalk_FreeWave(wavPtr);

            //再生
            using (var ms = new MemoryStream(wav_data))
                using (var sp = new SoundPlayer(ms)) {
                    sp.Play();
                }
        }
예제 #2
0
        static void Main()
        {
            while (true)
            {
                //不定長情報のメモリー確保
                IntPtr     aqtk_p     = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(AQTK_VOICE)));
                AQTK_VOICE aqtk_voice = (AQTK_VOICE)Marshal.PtrToStructure(aqtk_p, typeof(AQTK_VOICE));
                aqtk_voice.Init();

                //文字読み込み
                Console.WriteLine("何かひらがなを入れてください。");
                string koe = Console.ReadLine();
                System.Text.Encoding utf8Enc = System.Text.Encoding.GetEncoding("UTF-8");

                byte[] koeUtfBytes = utf8Enc.GetBytes(koe);

                int    size   = 0;
                IntPtr wavPtr = AquesTalk_Synthe_Utf8(ref aqtk_voice, koeUtfBytes, ref size);

                if (wavPtr == IntPtr.Zero)
                {
                }

                //C#であつかえるように
                byte[] wav_data = new byte[size];
                Marshal.Copy(wavPtr, wav_data, 0, size);

                //解放
                AquesTalk_FreeWave(wavPtr);

                //再生
                using (var ms = new MemoryStream(wav_data))
                    using (var sp = new SoundPlayer(ms))
                    {
                        sp.Play();
                    }
            }
        }
예제 #3
0
 extern static IntPtr AquesTalk_Synthe_Utf8(ref AQTK_VOICE pParam, byte[] koe, ref int size);