老规矩,先介绍一下 Unity 的科普小知识:
- Unity是 实时3D互动内容创作和运营平台 。
- 包括游戏开发、美术、建筑、汽车设计、影视在内的所有创作者,借助 Unity 将创意变成现实。
- Unity 平台提供一整套完善的软件解决方案,可用于创作、运营和变现任何实时互动的2D和3D内容,支持平台包括手机、平板电脑、PC、游戏主机、增强现实和虚拟现实设备。
- 也可以简单把 Unity 理解为一个游戏引擎,可以用来专业制作游戏!
-
🎬 博客主页:https://xiaoy.blog.csdn.net
-
🎥 本文由 呆呆敲代码的小Y 原创,首发于 CSDN🙉
-
🎄 学习专栏推荐:Unity系统学习专栏
-
🌲 游戏制作专栏推荐:游戏制作
-
🌲Unity实战100例专栏推荐:Unity 实战100例 教程
-
🏅 欢迎点赞 👍 收藏 ⭐留言 📝 如有错误敬请指正!
-
📆 未来很长,值得我们全力奔赴更美好的生活✨
-
------------------❤️分割线❤️-------------------------
在Unity中可以通过调用API检测可以从devices属性中获得已连接麦克风的列表 从而 判断有没有麦克风权限
Microphone
具体使用示例:
//获取麦克风设备,判断设备是否有麦克风
string[] devices = Microphone.devices;
if (devices.Length > 0)
{
Debug.Log("设备有麦克风:" + devices[0]);
}
else
{
Debug.Log("设备没有麦克风");
}
记录麦克风播放的声音API如下:
//
// 摘要:
// Start Recording with device.
//
// 参数:
// deviceName:
// The name of the device.
//
// loop:
// Indicates whether the recording should continue recording if lengthSec is reached,
// and wrap around and record from the beginning of the AudioClip.
//
// lengthSec:
// Is the length of the AudioClip produced by the recording.
//
// frequency:
// The sample rate of the AudioClip produced by the recording.
//
// 返回结果:
// The function returns null if the recording fails to start.
public static AudioClip Start(string deviceName, bool loop, int lengthSec, int frequency);
如果有麦克风权限则可以直接使用AudioSource播放,将脚本挂载到场景中并添加一个AudioSource组件拖到脚本上即可!
代码如下:
public AudioSource audioSource;
private void OnClick()
{
audioSource.clip = Microphone.Start(null, true, 10, 44100);
audioSource.Play();
}