前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【100个 Unity实用技能】| Unity中检测 设备麦克风权限

【100个 Unity实用技能】| Unity中检测 设备麦克风权限

作者头像
呆呆敲代码的小Y
发布2022-10-28 10:44:09
7610
发布2022-10-28 10:44:09
举报

Unity 小科普

老规矩,先介绍一下 Unity 的科普小知识:

  • Unity是 实时3D互动内容创作和运营平台 。
  • 包括游戏开发、美术、建筑、汽车设计、影视在内的所有创作者,借助 Unity 将创意变成现实。
  • Unity 平台提供一整套完善的软件解决方案,可用于创作、运营和变现任何实时互动的2D和3D内容,支持平台包括手机、平板电脑、PC、游戏主机、增强现实和虚拟现实设备。
  • 也可以简单把 Unity 理解为一个游戏引擎,可以用来专业制作游戏!

  • ???? 博客主页:https://xiaoy.blog.csdn.net
  • ???? 本文由 呆呆敲代码的小Y 原创,首发于 CSDN????
  • ???? 学习专栏推荐:Unity系统学习专栏
  • ???? 游戏制作专栏推荐:游戏制作
  • ????Unity实战100例专栏推荐:Unity 实战100例 教程
  • ???? 欢迎点赞 ???? 收藏 ⭐留言 ???? 如有错误敬请指正!
  • ???? 未来很长,值得我们全力奔赴更美好的生活✨
  • ------------------❤️分割线❤️-------------------------
请添加图片描述
请添加图片描述

Unity 实用小技能学习

Unity中 检测当前设备是否有麦克风权限

在Unity中可以通过调用API检测可以从devices属性中获得已连接麦克风的列表 从而 判断有没有麦克风权限

Microphone

在这里插入图片描述
在这里插入图片描述

方法

描述

End

停止记录。

GetDeviceCaps

获取设备的频率能力。

GetPosition

获取录音样本中的位置。

IsRecording

查询设备是否正在记录。

Start

开始记录设备。

具体使用示例:

        //获取麦克风设备,判断设备是否有麦克风
        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();
    }

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2022-10-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Unity 实用小技能学习
    • Unity中 检测当前设备是否有麦克风权限
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档