Unity中使用Windows的sapi进行语音朗读

在你的Unity项目中建立Plugins文件夹ide

将如下两个dll文件考入Plugins文件夹中code

CustomMarshalers.dll
Interop.SpeechLib.dllit

而后就能够在项目的C#脚本中进行使用了io

例:class

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SpeechLib;

public class Voice : MonoBehaviour
{
    private void Start()
        {
            SpVoice voice=new SpVoice();
            voice.Speak("你好");
        }
}

把脚本随便挂到场景中的任意物体上引用

运行场景,你就会听到稍显机械的女声读出“你好”脚本

注:不要在VS中添加引用speechlib,那样作没用,还报错项目

相关文章
相关标签/搜索