It’s not a matter of ‘have to’ it’s a matter of choosing the right tool for the job. Asterisk is a box of Lego’s – you get to choose the size and color of the blocks and arrange them as you see fit.
The ‘monitor’ application (and mixmonitor) start a recording. Your dialplan continues and your dialplan progresses. The recording continues until you explicitly stop it so ‘monitor’ is more useful to record a series of steps in your dialplan.
The ‘record’ application records until it ends by keystroke, timeout, or silence detection and then your dialplan continues. Since you said you want silence detection, that kind of makes the decision for you.
You also need to decide to write your application in ‘dialplan’ or as an AGI. They both have use cases. While I have a strong bias for writing applications as an AGI or a group of AGIs, I’d suggest you gain familiarity writing Asterisk applications in dialplan. One less technology to have to master at once.
Please try the following snippet:
[record-test]
exten = s,1, verbose(1,[${EXTEN}@${CONTEXT}])
same = n, record(/tmp/question.wav,3)
same = n, verbose(The status returned by record() is ${RECORD_STATUS})
same = n, playback(/tmp/question)
same = n, hangup()
When I execute this, I immediately (not 3 or 4 seconds later) get a beep, I speak, I stop speaking for 3 seconds, and I hear the recording of me speaking. My console log (with 'core set verbose 3) looks like:
-- Executing [s@record-test:1] Verbose("SIP/poly-77a1-00000006", "1,[s@record-test]") in new stack
[s@record-test]
-- Executing [s@record-test:2] Record("SIP/poly-77a1-00000006", "/tmp/question.wav,3") in new stack
-- <SIP/poly-77a1-00000006> Playing 'beep.gsm' (language 'en')
> 0x74208070 -- Strict RTP learning complete - Locking on source address 192.168.0.139:2238
-- Executing [s@record-test:3] Verbose("SIP/poly-77a1-00000006", "The status returned by record() is SILENCE") in new stack
The status returned by record() is SILENCE
-- Executing [s@record-test:4] Playback("SIP/poly-77a1-00000006", "/tmp/question") in new stack
-- <SIP/poly-77a1-00000006> Playing '/tmp/question.slin' (language 'en')
-- Executing [s@record-test:5] Hangup("SIP/poly-77a1-00000006", "") in new stack