Unity5.3 API 之 Microphone(游戏语音SDK )

本文详细介绍了Unity5.3 API中的Microphone接口,探讨了如何在游戏中集成和使用语音SDK,为游戏开发提供实时语音通信功能。
摘要由CSDN通过智能技术生成

Unity5.3 API 之 Microphone(游戏语音SDK )

好久不见,最近手机游戏内置语音越来越普遍,这样的需求也难免多了起来.对就是像微信/阴阳师那样.
下面介绍两种实现方法:
1.unity内置API - Microphone
2.第三方包SDK
3. - API - sealed class Microphine
优点:unity爸爸自己内置的,以后功能应该会更强大,避免接SDK,和第三方包的不稳定因素.
缺点:提供的方法太少,编码和解码需要自己搞定,优化不够到位,没有语音识别功能.
我推荐第二种方法,具体还是看需求!

第一种:unityAPI
API - sealed class Microphone

[C#] 纯文本查看 复制代码
namespace UnityEngine
{
    //
    // 摘要:
    //     ///
    //     Use this class to record to an AudioClip using a connected microphone.
    //     ///
    public sealed class Microphone
    {
        public Microphone();

        //
        // 摘要:
        //     ///
        //     A list of available microphone devices, identified by name.
        //     ///
        public static string[] devices { get; }

        //
        // 摘要:
        //     ///
        //     Stops recording.
        //     ///
        //
        // 参数:
        //   deviceName:
        //     The name of the device.
        [WrapperlessIcall]
        public static void End(string deviceName);
        [WrapperlessIcall]
        public static void GetDeviceCaps(string deviceName, out int minFreq, out int maxFreq);
        //
        // 摘要:
        //     ///
        //     Get the position in samples of the recording.
        //     ///
        //
        // 参数:
        //   deviceName:
        //     The name of the device.
        [WrapperlessIcall]
        public static int GetPosition(string deviceName);
        //
        // 摘要:
        //     ///
        //     Query if a device is currently recording.
        //     ///
        //
        // 参数:
        //   deviceName:
        //     The name of the device.
        [WrapperlessIcall]
        public static bool IsRecording(string deviceName);
        //
        // 摘要:
        //     ///
        //     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.
        //     ///
        [WrapperlessIcall]
        public static AudioClip Start(string deviceName, bool loop, int lengthSec, int frequency);
    }
}

开关录音
[C#] 纯文本查看 复制代码
 /// <summary>
    /// 开关录音
    /// </summary>
    /// <param name="isFlag"></param>
    public void StartMicro(bool isFlag)
    {
        if (Microphone.devices.Length < 0)
            return;

   
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值