博客
关于我
录音功能
阅读量:353 次
发布时间:2019-03-04

本文共 1543 字,大约阅读时间需要 5 分钟。

写在前面:

录音功能并不像是音频播放那样原本就有音频源,他是由纯脚本构成

1.页面组成

简单的UI制作界面如下图

在这里插入图片描述

2.录音音频

直接创建一个AudioSource,但是不给他挂在音频文件

3.创建一个c#脚本,脚本内容如下

using UnityEngine;public class TestAudio : MonoBehaviour{    AudioSource aud;///     ///保存录音文件    ///     // Start is called before the first frame update    void Start()    {        foreach(string device in Microphone.devices)        {            Debug.Log("Name:" + device);        }    }    // Update is called once per frame    void Update()    {            }    public void ButtonOnClick(int index)    {        if(index == 0)        {            aud = this.GetComponent
(); //如果传入的录音参数为0 aud.clip = Microphone.Start(Microphone.devices[0], true, 10, 44100);//开始录音 //参数代表的含义分别为1.目标设备的名称,是否循环录制,录制时间长短,录音品质需要注意的是 //无损音质的采样率=44100,即每秒音频用44100个float数据表示,但语音8000就够了(通常的移动电话=8000)。 } else if(index == 1)//如果传入的录音参数为1说明现在已经录音一段 { Microphone.End(Microphone.devices[0]); } else if(index == 2) { aud = this.GetComponent
(); aud.Play(); int min = 40000; int max = 44100; Debug.Log("播放状态" + IsRecording(Microphone.devices[0]));//输出当前的播放状态 Debug.Log("播放位置" + GetPosition(Microphone.devices[0]));//输出当前录音的位置 } } public bool IsRecording(string deviceName) { return IsRecording(deviceName); } public int GetPosition(string deviceName) { return GetPosition(deviceName); }}

将脚本挂在到AudioSource上,为Button绑定上监听事件,发布到手机上,即可使用录音功能。

转载地址:http://zbjr.baihongyu.com/

你可能感兴趣的文章
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>