- Home /
how to check if the user speak to microphone?
I want to check if the user speak to microphone (in c#). I searched easy way to do it and not found. I tried some libraries of audio but its not matched.
I need that the code will like:
if (user speak) speak=true;
else speak=false;
Is have easy way to do it?
Answer by CHPedersen · Jun 29, 2011 at 06:51 AM
This is a tough one, I'm afraid. As far as I know, there is no easy way to detect when the user speaks. There is no functionality in Unity for recording audio from a microphone, though plug-ins do exist if you have Unity Pro.
Even then, recording audio is just half the fun. You'd also need to figure out how to detect speech in the audio. If your app is used in quiet environments, I suppose you could simply trigger it when the recorded audio reaches above some threshold in dB, but if the app needs to work in noisy environments too, you'd need to analyze the signal somehow and see if it contains human speech.
I have Unity Pro. Where is plugins for microphone? The environment is quiet, how I can to check db?
thanks
It depends on what your platform is going to be. If you're developing for the iPhone, this plugin seems to do what you want:
If you're not on the iPhone however, things look somewhat more bleak. On windows, you can record audio in C# using calls to external, native functions in a dll-file called "winmm.dll". This project demonstrates how to do that:
http://www.codeproject.com/$$anonymous$$B/audio-video/SoundCatcher.aspx
The soundcatcher project has an FFT implementation that involves calculating decibels, to answer your other question.
Errr... I don't mean to be rude, but be warned that capturing audio this way is kind of hairy and sounds like it might be a little much for you. You might be better off altogether if you simply wait for the audio guys from Unity to offer this functionality inside Unity itself.
I succesed to record from microphone but I not know if the user speak. [DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
public static void record_voice()
{
mciSendString("open new Type waveaudio Alias recsound", "", 0, 0);
mciSendString("record recsound", "", 0, 0);
}
public static void savefile()
{
mciSendString("save recsound test.wav", "", 0, 0);
mciSendString("close recsound ", "", 0, 0);
}
I see FFT but I not understaned how it help me.
Answer by makisig.du · Sep 18, 2011 at 01:14 PM
I guess you already know that you can extend Unity's functionality through plugins and there are a number of plugins already available that you may use to detect mic input. However, if you're going to differentiate actual speech from any other auditory signal, then that's a whole new deal altogether.
My team took weeks putting together a cross-platform speech recognition plugin for Unity and all I can tell you now is that there is no easy way of doing it, unfortunately. At least, not at the time I posted this answer.
Maybe when it becomes more popular, Unity might consider including an API for it. For now, we had to make one.
Here's a sample of what we did. Don't hesitate to drop us a line if you want to discuss further.
Your answer
Follow this Question
Related Questions
What causes Microphone Start to not work, giving error result = 25? 0 Answers
Multiple Microphone Inputs 0 Answers
Get the device audio volume 0 Answers