华胜 发表于 2013-1-2 21:13

Unity引用DLL文件

using UnityEngine;
using System;
using System.Collections;
using System.Runtime.InteropServices;

public class VoiceSpeaker : MonoBehaviour
{
   
    private static extern int VoiceAvailable();
   
    private static extern void InitVoice();
   
    private static extern int WaitUntilDone(int millisec);
   
    private static extern void FreeVoice();
   
    private static extern int GetVoiceCount();
   
    private static extern string GetVoiceName(int index);
   
    private static extern void SetVoice(int index);
   
    private static extern void Say(string ttospeak);
   
    private static extern void SayAndWait(string ttospeak);
   
    private static extern int SpeakToFile(string filename, string ttospeak);
   
    private static extern int GetVoiceState();
   
    private static extern int GetVoiceVolume();
   
    private static extern void SetVoiceVolume(int volume);
   
    private static extern int GetVoiceRate();
   
    private static extern void SetVoiceRate(int rate);
   
    private static extern void PauseVoice();
   
    private static extern void ResumeVoice();

    public int voice_nb = 0;

    void Start()
    {
      if (VoiceAvailable() > 0)
      {
            InitVoice(); // init the engine
            Debug.Log("Number of voice : " + GetVoiceCount()); // Number of voice

            SetVoice(voice_nb); // 0 to voiceCount - 1

            Debug.Log("Voice name : " + GetVoiceName(voice_nb));
            Say("Hello. I can speak now. My name is " + GetVoiceName(voice_nb) + ". Welcome to Unity"+"Ãû×Ö");
      }
    }

    void OnDisable()
    {
      if (VoiceAvailable() > 0)
      {
            FreeVoice();
      }
    }
}

aaabbbsss12345 发表于 2014-5-27 10:56

好东西 好东西

yezhinet 发表于 2017-4-8 21:47

楼主是超人

venuzzz 发表于 2017-4-8 21:50

顶顶多好

xiaohei 发表于 2017-4-8 21:46

难得一见的好帖

cgfr 发表于 2017-4-8 21:41

很好哦

venuzzz 发表于 2017-4-8 22:02

LZ真是人才

killcih 发表于 2017-6-18 21:00

好帖就是要顶

千江月 发表于 2017-6-18 20:31

顶顶多好

李上隐 发表于 2017-6-18 20:33

难得一见的好帖
页: [1]
查看完整版本: Unity引用DLL文件