-
[3D] 마이크 기능 구현(음성 채팅)Unity(유니티) 2022. 5. 4. 10:44
- Microphone.Start
public static AudioClip.Start(string deviceName, bool loop, int lengthSec, int frequency);
AudioSource를 게임오브젝트에 추가해주고 참조
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Mic : MonoBehaviour { public AudioSource mic; //마이크로 녹음된 소리를 재생할 오디오소스 컴포넌트 void Start() { //컴퓨터에 등록된 마이크를 배열에 등록 string[] myMic = Microphone.devices; for(int i = 0; i < myMic.Length; i++) { Debug.Log(Microphone.devices[i].ToString()); } } void Update() { if (Input.GetKeyDown(KeyCode.F)) { //오디오 소스 클립에 마이크값을 지정(배열 안에 숫자를 통해 마이크 선택) //100과 44100은 음량 관련 값 mic.clip = Microphone.Start(Microphone.devices[0].ToString(), true, 100, 44100); //딜레이를 줄이기 위해 추가한 코드 while (!(Microphone.GetPosition(null) > 0)) { } //마이크 녹음 재생 mic.Play(); } if (Input.GetKeyDown(KeyCode.G)) { mic.Stop(); } } }
'Unity(유니티)' 카테고리의 다른 글
[Prototype2] 랜덤 동물 스폰(InvokeRepeating) (0) 2022.05.12 [3D] Recorder 사용하기 (영상 및 사진 파일로 저장, 녹음, 캡처) (0) 2022.05.04 [3D] WebCam 구현 (0) 2022.05.04 [3D] Raycast 활용하기(Ray, RaycastHit,Instantiate) (0) 2022.04.22 [JohnLemon 3D] 첫 번째 스크립트 작성하기(void Start) (0) 2022.04.20