Sound trigger the beginning of its recording?

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?

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?

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.

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?

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.

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

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?

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?

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.

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?

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

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?

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.

You can start recording with System::recordStart, this will record into an FMOD::Sound. You can access the audio directly by calling Sound::lock. This is quite low level, you’ll need to monitor 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.