欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Unity調(diào)取移動(dòng)端的麥克風(fēng)進(jìn)行錄音并播放

 更新時(shí)間:2020年04月16日 11:10:38   作者:幻世界  
這篇文章主要為大家詳細(xì)介紹了Unity調(diào)取移動(dòng)端的麥克風(fēng)進(jìn)行錄音并播放,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Unity調(diào)取移動(dòng)端的麥克風(fēng)進(jìn)行錄音并播放的具體代碼,供大家參考,具體內(nèi)容如下

1.對MicroPhone類的理解

對麥克風(fēng)的調(diào)用在Unity里主要是用到了MicroPhone這個(gè)類,此類里面有幾個(gè)方法可以方便我們實(shí)現(xiàn)功能

2.代碼演示

#region 模塊信息
// **********************************************************************
// Copyright (C) 2018 Blazors
// Please contact me if you have any questions
// File Name:  VoiceChat
// Author:  romantic123fly
// WeChat||QQ:  at853394528 || 853394528 
// **********************************************************************
#endregion
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
 
 
//此腳本須掛在錄音按鈕上
public class Record : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
 float tirecordingTimemer = 0;//錄音時(shí)長限制
 public AudioSource aud;//存儲(chǔ)聲音
 public Text ShowTimeHint;//剩余時(shí)間的文字提示
 public void OnPointerDown(PointerEventData eventData)
 {
 Debug.Log("Start");
 StartCoroutine("KeepTime");
 aud.clip = Microphone.Start("Built-in Microphone", false, 60, 44100);
 }
 public void OnPointerUp(PointerEventData eventData)
 {
 Microphone.End("Built-in Microphone");
 StopCoroutine("KeepTime");
 Debug.Log("Over");
 aud.Play();
 }
 //此處開攜程也行,用while也可以,放在updata里也沒問題
 IEnumerator KeepTime()
 {
 for (tirecordingTimemer = 10; tirecordingTimemer >= 0; tirecordingTimemer -= Time.deltaTime)
 {
  if (tirecordingTimemer <= 10)
  {
  ShowTimeHint.text = "你還可以錄 " + (int)tirecordingTimemer + " 秒";
  if (tirecordingTimemer < 1)
  {
   ShowTimeHint.text = "時(shí)間到";
   Microphone.End("Built-in Microphone");
  }
  }
  yield return 0;
 }
 }
}

對應(yīng)的ui組件掛靠一下直接運(yùn)行工程就好了

3.運(yùn)行結(jié)果

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論