Pergunta

In my application, any phone can voice-connect to my 3G USB modem and the call gets picked up immediately. It receives audio as PCM (8000 samples, 16 bits, mono) through a serial port and uses Microsoft's Speech Synthesizer to talk back to the caller.

The problem is, the application should talk back only when the caller has stopped speaking. How can I detect that ?

I tried implementing a 3-second timer which resets itself when data is received from the serial port, so when the timer gets 'ticked' it should mean that that the caller was silent for 3 seconds. But it doesn't work that way. What did I do wrong ?

private void DataRecdFromSerial(object sender, SerialDataReceivedEventArgs e)
{
     say.Stop(); say.Start(); // reset timer with interval 5000
     int n = usb.BytesToRead;
     byte[] comBuffer = new byte[90000];
     usb.Read(comBuffer, 0, n);
     if(comBuffer.Length > 0)
     {  
          wfw.Write(comBuffer, 0, n); // NAudio Wave File Writer
     }
}

private void say_Tick(object sender, EventArgs e)
{
     // Caller stopped speaking for 5 seconds (not working)
 }
Foi útil?

Solução

By what magic on earth should data flow interrupt when there is silence ? you will get a continuous stream as long as the line is connected that is the most logical of all software and electronical engineering implementation that one can excpect today. So you need to analyze the spectrum of the sound wave and calculate root mean square amplitude to get energy. you compare to a threshold that you fix by empirical testing (because silence is actually a small noise that you need to accept).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top