Unity中使用Windows的sapi进行语音朗读
更新:HHH   时间:2023-1-7


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

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

CustomMarshalers.dll
Interop.SpeechLib.dll

然后就可以在项目的C#脚本中进行使用了

例:

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,那样做没用,还报错

返回游戏开发教程...