找回密码
 立即注册
楼主: 华胜

[脚本] Unity引用DLL文件

[复制链接]
发表于 2013-1-2 21:13 | 显示全部楼层 |阅读模式
  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4. using System.Runtime.InteropServices;

  5. public class VoiceSpeaker : MonoBehaviour
  6. {
  7.     [DllImport("Voice_speaker.dll", EntryPoint = "VoiceAvailable")]
  8.     private static extern int VoiceAvailable();
  9.     [DllImport("Voice_speaker.dll", EntryPoint = "InitVoice")]
  10.     private static extern void InitVoice();
  11.     [DllImport("Voice_speaker.dll", EntryPoint = "WaitUntilDone")]
  12.     private static extern int WaitUntilDone(int millisec);
  13.     [DllImport("Voice_speaker.dll", EntryPoint = "FreeVoice")]
  14.     private static extern void FreeVoice();
  15.     [DllImport("Voice_speaker.dll", EntryPoint = "GetVoiceCount")]
  16.     private static extern int GetVoiceCount();
  17.     [DllImport("Voice_speaker.dll", EntryPoint = "GetVoiceName")]
  18.     private static extern string GetVoiceName(int index);
  19.     [DllImport("Voice_speaker.dll", EntryPoint = "SetVoice")]
  20.     private static extern void SetVoice(int index);
  21.     [DllImport("Voice_speaker.dll", EntryPoint = "Say")]
  22.     private static extern void Say(string ttospeak);
  23.     [DllImport("Voice_speaker.dll", EntryPoint = "SayAndWait")]
  24.     private static extern void SayAndWait(string ttospeak);
  25.     [DllImport("Voice_speaker.dll", EntryPoint = "SpeakToFile")]
  26.     private static extern int SpeakToFile(string filename, string ttospeak);
  27.     [DllImport("Voice_speaker.dll", EntryPoint = "GetVoiceState")]
  28.     private static extern int GetVoiceState();
  29.     [DllImport("Voice_speaker.dll", EntryPoint = "GetVoiceVolume")]
  30.     private static extern int GetVoiceVolume();
  31.     [DllImport("Voice_speaker.dll", EntryPoint = "SetVoiceVolume")]
  32.     private static extern void SetVoiceVolume(int volume);
  33.     [DllImport("Voice_speaker.dll", EntryPoint = "GetVoiceRate")]
  34.     private static extern int GetVoiceRate();
  35.     [DllImport("Voice_speaker.dll", EntryPoint = "SetVoiceRate")]
  36.     private static extern void SetVoiceRate(int rate);
  37.     [DllImport("Voice_speaker.dll", EntryPoint = "PauseVoice")]
  38.     private static extern void PauseVoice();
  39.     [DllImport("Voice_speaker.dll", EntryPoint = "ResumeVoice")]
  40.     private static extern void ResumeVoice();

  41.     public int voice_nb = 0;

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

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

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

  53.     void OnDisable()
  54.     {
  55.         if (VoiceAvailable() > 0)
  56.         {
  57.             FreeVoice();
  58.         }
  59.     }
  60. }

复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
发表于 2014-5-27 10:56 | 显示全部楼层
好东西 好东西
发表于 2017-4-8 21:47 | 显示全部楼层
楼主是超人
发表于 2017-4-8 21:50 | 显示全部楼层
顶顶多好
发表于 2017-4-8 21:46 | 显示全部楼层
难得一见的好帖
发表于 2017-4-8 21:41 | 显示全部楼层
很好哦
发表于 2017-4-8 22:02 | 显示全部楼层
LZ真是人才
发表于 2017-6-18 21:00 | 显示全部楼层
好帖就是要顶
发表于 2017-6-18 20:31 | 显示全部楼层
顶顶多好
发表于 2017-6-18 20:33 | 显示全部楼层
难得一见的好帖
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-5-5 23:57 , Processed in 0.102388 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表