
How to Get Accurate Recording Duration from Unity's Microphone
Introduction I was building a voice recording feature using a smartphone microphone in Unity. The requirement was simple: tap a button to start recording, tap again to stop. However, I ran into a problem — I couldn't get the accurate recording duration. This article explains how I solved it. Unity's Microphone Class Unity provides a built-in Microphone class for recording audio. Unity Documentation | Microphone On iPhone, Android, and Mac, it uses the built-in microphone. On Windows, Unity will detect any connected microphone automatically (probably). Sample Code (Updated: 2018/10/21) I created a sample Unity project. Feel free to use it. https://github.com/segurvita/UnityMicrophonePractice It supports starting/stopping recording and playback via button controls. Code Walkthrough Here is the full sample code: using UnityEngine ; public class RecordManager : MonoBehaviour { // Public variables public int maxDuration ; // Maximum recording duration (e.g., 20 seconds) public AudioClip aud
Continue reading on Dev.to
Opens in a new tab




