zoukankan      html  css  js  c++  java
  • Unity实现手机录音功能

    using UnityEngine;
    using System.Collections;

    public class MicPhoneScripts : MonoBehaviour
    {
        private AudioSource audioSource;
        AudioClip clip;
        void Awake()
        {
            audioSource = GetComponent<AudioSource>();
            
        }
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                StartRecord();

            }
            if (Input.GetKeyUp(KeyCode.Space))
            {
                StopRecord();
            }
        }

        /// <summary>
        /// 开始录音
        /// </summary>
      public   void StartRecord()
        {
            Microphone.End(null);
            clip = Microphone.Start(null, false, 20, 8000);
        }
        /// <summary>
        /// 结束录音
        /// </summary>
      public   void StopRecord()
        {
            if (Microphone.IsRecording(null))
            {
                Microphone.End(null);
                audioSource.clip = clip;
                audioSource.Play();
            }
        }
    }

    注:UI中绑定StartRecord()和StopRecord()方法 打包到手机即可

  • 相关阅读:
    ajax请求超时
    tp5去重统计某字段的数量
    html本地存储 localStorge
    json、obj转换
    关于数组的合并arr.push() arr.push.apply()
    curl内容
    js 回车键登录
    tp5 前置操作
    STL容器
    c++文件的读写
  • 原文地址:https://www.cnblogs.com/ningyongbin/p/6006564.html
Copyright © 2011-2022 走看看