# Sound trigger the beginning of its recording?

**URL:** https://qa.fmod.com/t/sound-trigger-the-beginning-of-its-recording/17479
**Category:** Unity
**Tags:** android
**Created:** [July 26, 2021, 9:10pm UTC](https://qa.fmod.com/t/sound-trigger-the-beginning-of-its-recording/17479 "2021-07-26T21:10:07Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Danielkotzer](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Danielkotzer](https://qa.fmod.com/u/Danielkotzer)
#### Post date: [July 26, 2021, 9:10pm UTC](https://qa.fmod.com/t/sound-trigger-the-beginning-of-its-recording/17479/1 "2021-07-26T21:10:07Z")

</div>

Hi,

Is there a way I can make a sound trigger the beginning of its recording? and the end of the sound trigger the stop of the recording? Like the toys I’ve seen of a toy parrot that you can say a word, and it is repeating it once you stop talking to it. Is there a way to do it on unity and Fmod on a build that run on Android/iPhone?

Can the Fmod extension for unity do this – trigger an event when a sound is starting to be heard? and another event when it starts to silent and there is no sound? On a build on iOS and Android?

---

<div class="post-metadata">

### Author: ![Alcibiade](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/alcibiade/32/4284_2.png) [@Alcibiade](https://qa.fmod.com/u/Alcibiade)
#### Post date: [July 27, 2021, 12:38pm UTC](https://qa.fmod.com/t/sound-trigger-the-beginning-of-its-recording/17479/2 "2021-07-27T12:38:45Z")

</div>

Can you be more specific about what you’re trying to achieve? Do you want that the user talks in a mic and the program records the sound and stops automatically when he’s finished? Why do you talk about “another event” at the end of the sound?

---

<div class="post-metadata">

### Author: ![Danielkotzer](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Danielkotzer](https://qa.fmod.com/u/Danielkotzer)
#### Post date: [July 27, 2021, 1:15pm UTC](https://qa.fmod.com/t/sound-trigger-the-beginning-of-its-recording/17479/3 "2021-07-27T13:15:33Z")

</div>

What I need right now is to know when the sound has started and when it has stopped, and measure the time in-between. At a later stage I might want to be able to recognize the characteristics of this sound, therefore I want to be able to have access to the bit array or the raw data of this sound file, that is why I want the app to record it as well, but to begin working on my app, I need only to be able to measure the duration of the sound, from the moment it starts to the moment it ends, and have a timer running on screen.

---

<div class="post-metadata">

### Author: ![Alcibiade](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/alcibiade/32/4284_2.png) [@Alcibiade](https://qa.fmod.com/u/Alcibiade)
#### Post date: [July 27, 2021, 1:27pm UTC](https://qa.fmod.com/t/sound-trigger-the-beginning-of-its-recording/17479/4 "2021-07-27T13:27:45Z")

</div>

I’m still not sure I got it. Maybe do you want FMOD to send a callback to Unity when the event is automatically stopped (by not having anymore sound to play), so you can measure the delay between the moment you started the event until there?

---

<div class="post-metadata">

### Author: ![Danielkotzer](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Danielkotzer](https://qa.fmod.com/u/Danielkotzer)
#### Post date: [July 27, 2021, 1:33pm UTC](https://qa.fmod.com/t/sound-trigger-the-beginning-of-its-recording/17479/5 "2021-07-27T13:33:53Z")

</div>

I want the app is measuring the duration of the sound that is heard next to it with a timer. But I don’t want the user to have to click on a button to start the timer, I want the app to start and stop it by itself, by detecting when a sound is heard and when it stopped being heard.

---

<div class="post-metadata">

### Author: ![Alcibiade](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/alcibiade/32/4284_2.png) [@Alcibiade](https://qa.fmod.com/u/Alcibiade)
#### Post date: [July 27, 2021, 1:36pm UTC](https://qa.fmod.com/t/sound-trigger-the-beginning-of-its-recording/17479/6 "2021-07-27T13:36:56Z")

</div>

So a sound recorded in real time by the device’s mic?

---

<div class="post-metadata">

### Author: ![Danielkotzer](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Danielkotzer](https://qa.fmod.com/u/Danielkotzer)
#### Post date: [July 27, 2021, 1:38pm UTC](https://qa.fmod.com/t/sound-trigger-the-beginning-of-its-recording/17479/7 "2021-07-27T13:38:50Z")

</div>

Yes, but a timer should be seen when the silence stopped by a sound, and the timer stopes when it is silent again, can fmod detect when the environment is silent and when not?

---

<div class="post-metadata">

### Author: ![Danielkotzer](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Danielkotzer](https://qa.fmod.com/u/Danielkotzer)
#### Post date: [July 27, 2021, 1:41pm UTC](https://qa.fmod.com/t/sound-trigger-the-beginning-of-its-recording/17479/8 "2021-07-27T13:41:14Z")

</div>

I guess my question was not clear, there has to be a recording going on all the time, but I need to be able to detect when a sound is heard, on the record, and when there is noting recording, only silent. can this be done?

---

<div class="post-metadata">

### Author: ![Alcibiade](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/alcibiade/32/4284_2.png) [@Alcibiade](https://qa.fmod.com/u/Alcibiade)
#### Post date: [July 27, 2021, 1:55pm UTC](https://qa.fmod.com/t/sound-trigger-the-beginning-of-its-recording/17479/9 "2021-07-27T13:55:21Z")

</div>

Though I could be wrong, I’m really not aware FMOD is capable of receiving a continuous stream of audio from outside, and react to it in real time.

---

<div class="post-metadata">

### Author: ![Danielkotzer](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Danielkotzer](https://qa.fmod.com/u/Danielkotzer)
#### Post date: [July 27, 2021, 3:17pm UTC](https://qa.fmod.com/t/sound-trigger-the-beginning-of-its-recording/17479/10 "2021-07-27T15:17:30Z")

</div>

I saw someone make an application, with Unity and fmod, that is recording the user voice and plays it in a slight delay, which is creating an echo effect, all I need to know if I can have access to the raw data of the recording, in real time, and look at the pick of the sound wave to know if there is silent or somethings is being heard, can anyone help me please?

---

<div class="post-metadata">

### Author: ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)
#### Post date: [July 29, 2021, 1:01am UTC](https://qa.fmod.com/t/sound-trigger-the-beginning-of-its-recording/17479/11 "2021-07-29T01:01:48Z")

</div>

This is possible but it requires a complicated setup of maintaining two separate FMOD systems - one for recording and one to play back the chunk of recorded data.

In terms of detecting signal you will need to use DSP::setMeteringEnabled() at the Core API level in order to get this information.

[https://fmod.com/resources/documentation-api?version=2.00&page=core-api-dsp.html#dsp\_setmeteringenabled](https://fmod.com/resources/documentation-api?version=2.00&page=core-api-dsp.html#dsp_setmeteringenabled)

---

<div class="post-metadata">

### Author: ![Danielkotzer](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Danielkotzer](https://qa.fmod.com/u/Danielkotzer)
#### Post date: [July 29, 2021, 6:08pm UTC](https://qa.fmod.com/t/sound-trigger-the-beginning-of-its-recording/17479/12 "2021-07-29T18:08:19Z")

</div>

I’ve seen the link, but can’t find any examples on how this can be done. Seems to me that Fmod has an internal logic that takes time to learn, and there are not so many examples online that I can learn from. Maybe you can show me an example of how I use SetMeteringEnabled to detect the loudness of the sound recorded on the mic?

---

<div class="post-metadata">

### Author: ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)
#### Post date: [August 2, 2021, 1:44am UTC](https://qa.fmod.com/t/sound-trigger-the-beginning-of-its-recording/17479/13 "2021-08-02T01:44:35Z")

</div>

Unfortunately creating and maintaining two separate FMOD systems is a rather difficult technique even for an advanced user. It will take a lot more than a Q&A post in order to explain with examples, but the general idea is to have two systems created, one looking after playing & recording events and one that reads the chunks of recorded data back.

In terms of using the `setMeteringEnabled` you will need to use the DSP head of the ChannelGroup of where you are recording the mic. Then you can enable the metering here and grab the data as needed. Unfortunately this is another “too big for a single post” answer, but you can look into using DSPs in the `dsp_effect_per_speaker.cpp` example in the FMOD API installation.

---

<div class="post-metadata">

### Author: ![mathew](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mathew/32/431_2.png) [@mathew](https://qa.fmod.com/u/mathew)
#### Post date: [August 3, 2021, 6:22am UTC](https://qa.fmod.com/t/sound-trigger-the-beginning-of-its-recording/17479/14 "2021-08-03T06:22:31Z")

</div>

You can start recording with [System::recordStart](https://fmod.com/resources/documentation-api?version=2.01&page=core-api-system.html#system_recordstart), this will record into an FMOD::Sound. You can access the audio directly by calling [Sound::lock](https://fmod.com/resources/documentation-api?version=2.01&page=core-api-sound.html#sound_lock). This is quite low level, you’ll need to monitor [System::getRecordPosition](https://fmod.com/resources/documentation-api?version=2.01&page=core-api-system.html#system_getrecordposition) to know which parts of the FMOD::Sound have been written to and processing the audio to detect silence / words is a process you’ll need to implement yourself.

We have two C++ examples for this stuff, “record” and “record\_enumeration”, these are part of the Core API examples shipping with our API installer. While using this API in C# for Unity is possible, we don’t provide examples for it.
