- 最后登录
- 2014-10-23
- 注册时间
- 2011-7-19
- 阅读权限
- 90
- 积分
- 81303
 
- 纳金币
- -1
- 精华
- 11
|
代码:
// Voice Speaker (c) ZJP //
using UnityEngine;
using System;
using System.Collections;
using System.Runtime.Interopservices;
public class VoiceSpeaker : MonoBehaviour
{
[DllImport ("Voice_speaker.dll", EntryPoint="VoiceAvailable")] private static extern int VoiceAvailable();
[DllImport ("Voice_speaker.dll", EntryPoint="InitVoice")] private static extern void InitVoice();
[DllImport ("Voice_speaker.dll", EntryPoint="WaitUntilDone")] private static extern int WaitUntilDone(int millisec);
[DllImport ("Voice_speaker.dll", EntryPoint="FreeVoice")] private static extern void FreeVoice();
[DllImport ("Voice_speaker.dll", EntryPoint="GetVoiceCount")] private static extern int GetVoiceCount();
[DllImport ("Voice_speaker.dll", EntryPoint="GetVoiceName")] private static extern string GetVoiceName(int index);
[DllImport ("Voice_speaker.dll", EntryPoint="SetVoice")] private static extern void SetVoice(int index);
[DllImport ("Voice_speaker.dll", EntryPoint="Say")] private static extern void Say(string ttospeak);
[DllImport ("Voice_speaker.dll", EntryPoint="SayAndWait")] private static extern void SayAndWait(string ttospeak);
[DllImport ("Voice_speaker.dll", EntryPoint="SpeakToFile")] private static extern int SpeakToFile(string filename, string ttospeak);
[DllImport ("Voice_speaker.dll", EntryPoint="GetVoiceState")] private static extern int GetVoiceState();
[DllImport ("Voice_speaker.dll", EntryPoint="GetVoiceVolume")] private static extern int GetVoiceVolume();
[DllImport ("Voice_speaker.dll", EntryPoint="SetVoiceVolume")] private static extern void SetVoiceVolume(int volume);
[DllImport ("Voice_speaker.dll", EntryPoint="GetVoiceRate")] private static extern int GetVoiceRate();
[DllImport ("Voice_speaker.dll", EntryPoint="SetVoiceRate")] private static extern void SetVoiceRate(int rate);
[DllImport ("Voice_speaker.dll", EntryPoint="auseVoice")] private static extern void PauseVoice();
[DllImport ("Voice_speaker.dll", EntryPoint="ResumeVoice")] 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();
}
}
}Win32 Standalone. Unity 2.6.1 PRO and Indie.
Unity 3 PRO only. System.Runtime.InteropServices is deactivate in the free version.
As far i know, this is the ONLY development tool under Windows (2d or 3d, Free or Not), which does not allow access to native DLLs. Mesquinerie !!!
原地址:http://f***m.unity3d.com/threads/56038-Text-to-Speech-Dll-for-Win32 |
|