查看: 2341|回复: 1
打印 上一主题 下一主题

unity3d语音朗读扩展

[复制链接]

5552

主题

2

听众

8万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
11

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2012-3-14 14:30:28 |只看该作者 |倒序浏览
Unity (Indie and Pro) can speak now. Sorry, only for Windows standalone  

Just place the Dll in the windows/system32 folder
The "VoiceSpeaker.CS" file
代码如下:
// 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();

        }

    }

}

所调用的 dll文件在附件中
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

797

主题

1

听众

1万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
5568
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

沙发
发表于 2012-3-16 19:40:35 |只看该作者

   
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-7-13 23:09 , Processed in 0.063930 second(s), 32 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部