You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.1 KiB
51 lines
1.1 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using System; |
|
using System.IO; |
|
|
|
[RequireComponent(typeof(AudioRecorder))] |
|
public class AudioRecorderTest : MonoBehaviour |
|
{ |
|
public string AudioFile; |
|
|
|
private AudioRecorder recorder; |
|
|
|
void Start() |
|
{ |
|
recorder = GetComponent<AudioRecorder>(); |
|
|
|
recorder.Stopped += OnRecorderStopped; |
|
} |
|
|
|
private void OnDestroy() |
|
{ |
|
recorder.Stopped -= OnRecorderStopped; |
|
} |
|
|
|
private void OnRecorderStopped(ArraySegment<byte> segment) |
|
{ |
|
|
|
using (var filestream = new FileStream("TEST.opus", FileMode.CreateNew)) |
|
{ |
|
filestream.Write(segment.Array, segment.Offset, segment.Count); |
|
} |
|
} |
|
|
|
private void OnGUI() |
|
{ |
|
GUILayout.BeginArea(new Rect(0, 0, 200, 600)); |
|
GUILayout.BeginVertical(); |
|
|
|
GUILayout.Label("录音机测试:"); |
|
|
|
if (GUILayout.Button("开始录音")) |
|
recorder.StartRecorder(); |
|
|
|
if (GUILayout.Button("停止录音")) |
|
recorder.StopRecorder(); |
|
|
|
GUILayout.EndVertical(); |
|
GUILayout.EndArea(); |
|
} |
|
} |