国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

Unity調取移動端的麥克風進行錄音并播放

2020-01-24 00:04:21
字體:
來源:轉載
供稿:網友

本文實例為大家分享了Unity調取移動端的麥克風進行錄音并播放的具體代碼,供大家參考,具體內容如下

1.對MicroPhone類的理解

對麥克風的調用在Unity里主要是用到了MicroPhone這個類,此類里面有幾個方法可以方便我們實現功能

2.代碼演示

#region 模塊信息// **********************************************************************// Copyright (C) 2018 Blazors// Please contact me if you have any questions// File Name:    VoiceChat// Author:    romantic123fly// WeChat||QQ:   at853394528 || 853394528 // **********************************************************************#endregionusing System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.EventSystems;using UnityEngine.UI;  //此腳本須掛在錄音按鈕上public class Record : MonoBehaviour, IPointerDownHandler, IPointerUpHandler{ float tirecordingTimemer = 0;//錄音時長限制 public AudioSource aud;//存儲聲音 public Text ShowTimeHint;//剩余時間的文字提示 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 = "時間到";     Microphone.End("Built-in Microphone");    }   }   yield return 0;  } }}

對應的ui組件掛靠一下直接運行工程就好了

3.運行結果

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 吐鲁番市| 连州市| 炉霍县| 台山市| 山丹县| 普安县| 来凤县| 高邑县| 德庆县| 阳曲县| 阳信县| 普格县| 塔河县| 临猗县| 镶黄旗| 曲沃县| 西宁市| 苍溪县| 青冈县| 苗栗市| 澄城县| 确山县| 科技| 逊克县| 乐业县| 澎湖县| 天台县| 德江县| 裕民县| 长子县| 张北县| 印江| 绍兴县| 东辽县| 东乌珠穆沁旗| 清镇市| 高邮市| 墨江| 清水县| 彭水| 镇康县|