Microphone.start(), need lengthsec unfixed value, is possible?
Hi,
Unity advise me microphone.start use like this audio.clip = Microphone.Start(null, false, 7, 44100);
But I don't want to fixed value, I have two button, start recording and stop recording.
So i want detect user click the button for stop recording.(<- this is ok.)
how can i use unfixed_value at microphone.(Microphone.Start(null, false, unfixed_value, 44100); )
I don't know total recording times. Please help me. give me any advise plz.
Answer by robot55 · Aug 11, 2017 at 06:51 AM
I had similar issues - as you mentioned, having a "stop" button that executes Microphone.End(null); will stop the recording.
so what you need to od, IMO, is set the lengthSec in Microphone.Start to be very long (180 would mean 3 minutes for instance). Any length that would be larger than what user would need (1800 would give you 30 minutes, 18000 = 300 minutes or whatever you think is enough) Note that when user play the stop butoon - the clip length would be from Microphone.Start to Microphone.End (stop button clicked) and not the initial value you entered.
I am asusming Unity decided you must enter a length in order to avoid performance, file-size and (maybe) privacy issues - so there will never be a recording that lasts forever. (Note that legthSec is an INT. If it was a float - you could set it to MathF.Infinity)
TL;DR: Just set legthSec to something bigger than what user will ever need - and all your clips legth would be set to when the stop button is clicked. This should give you what you need.
hope that helps. Robot55
Hi, correcting mistake - what I wrote above is no longer accurate. In order to shorten the clip.length to the actual recording you need to create some "EndRecording" function - involves copying the actual recorded data to a new AudioClip. See here
Your answer
![](https://koobas.hobune.stream/wayback/20220612110005im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Trying to use derive pitch and db from realtime microphone input 0 Answers
Trying to use derive pitch and db from realtime microphone input 0 Answers
Newbie with OnTriggerEnter & Audio Files 0 Answers
how do i destroy object on trigger with sound in unity 5.2.2? 1 Answer
I want the audio to play when the player nears the object, but fade away when they walk away. 0 Answers