Note:这种方法只用于学习,没有任何实际意义。
如果需要实现录音,可以使用原生的接口,Android就去找Android,IOS就去找IOS。最方便的方式是接入语音SDK,比如百度语音SDK。
目标实现录音功能、保存为wav、播放、保存为int16[]发送网络数据流、接收Int16[]播放数据流
MicroPhoneInput类
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;using UnityEngine;using System.Collections;[RequireComponent (typeof(AudioSource))]public class MicroPhoneInput : MonoBehaviour { private static MicroPhoneInput m_instance; public float sensitivity=100; public float loudness=0; private static string[] micArray=null; const int HEADER_SIZE = 44; const int RECORD_TIME = 10; // Use this for initialization void Start () { } public static MicroPhoneInput getInstance() { if (m_instance == null) { micArray = Microphone.devices; if (micArray.Length == 0) { Debug.LogError ("Microphone.devices is null"); } foreach (string deviceStr in Microphone.devices) { Debug.Log("device name = " + deviceStr); } if(micArray.Length==0) { Debug.LogError("no mic device"); } &n