Unity中使用Windows的sapi进行语音朗读
在你的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,那样做没用,还报错
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。