Use voice frequency detection via microphone and set up audio recording

Hi my friends
I have a problem, I want to use <FreqMeasure.h> library to measuring the frequency of the voice at first, then use
<TMRpcm.h> library for recording audio after receiving the first frequency between a specified area, but my problem is that when I’m using just one microphone to detect the frequency and recording the audio at the same time, at this code I attached here, in this line :

if (frequency > 70) { StartRecord();
}

It works well as long as the received frequency is less than 70, but only when the frequency is higher than 70, at this line :

void StartRecord() {
  digitalWrite(2, HIGH); audio.startRecording("1.wav", 16000, A0);
}

this code is activated <audio.startRecording(“1.wav”, 16000, A0);> and then it stops at this point, and after that, it no longer detects the frequency or records!
I think the problem is that in this code at the same time from a microphone is not able to detect the frequency and record it

Do you think, dear ones, that my method for detecting frequency and then recording it is approved or is it difficult at all?
I’m a beginner at Arduino coding
I’m sorry if we misspell some parts because I’m not English :’(
thanks a lot…

#include <FreqMeasure.h>
#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 10
TMRpcm audio;

double sum = 0;
int count = 0;
bool state = false;
int frequency = 0;
int continuity = 0;
int i = 0;
int val = 0;

void setup() {
  Serial.begin(9600);
  FreqMeasure.begin();
  pinMode(2, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(A0, INPUT);
  digitalWrite(7, HIGH);

  if (!SD.begin(SD_ChipSelectPin)) {
    return;
  } else {
    Serial.println("SD OK");
  }

  audio.CSPin = SD_ChipSelectPin;
}

void loop() {

  val = digitalRead(8);
  if (FreqMeasure.available()) {

    sum = sum + FreqMeasure.read();
    count = count + 1;
    if (count > 30) {
      frequency = FreqMeasure.countToFrequency(sum / count);
      Serial.println(frequency);
      sum = 0;
      count = 0;
    }

  }


  if (frequency > 70) {

    StartRecord();

  }

  else {

    StopRecord();
  }
}

void StartRecord() {
  digitalWrite(2, HIGH);

  audio.startRecording("1.wav", 16000, A0);

}

void StopRecord() {
  digitalWrite(2, LOW);
  audio.stopRecording("1.wav");
}

are you using an arduino, esp32, some digital signal processor?
i didn't think these microcontrollers had the ability to properly sample speech (~8kHz)

I'm using Arduino UNO and a ky-037 microphone
I just use this method to record voices with a frequency between a specified area, if possible!

what freq do you sample at, how do you do it periodically and what is your anti-aliasing filter?

For example, I generated a frequency between 70 and 80 by the software and gave it to the microphone,
And then with this line :

if (FreqMeasure.available()) {

    sum = sum + FreqMeasure.read();
    count = count + 1;
    if (count > 30) {
      frequency = FreqMeasure.countToFrequency(sum / count);
      Serial.println(frequency);
      sum = 0;
      count = 0;
    }

  }

It can detect the frequency periodically and start and stop recording the sound accordingly (of course, this is my general opinion and so far, as I mentioned, I have a problem!)

And about the anti-aliasing filter, so far I have not done anything special except using the Ky-037 microphone module

Do you think this is feasible?

is it difficult at all?

It is very difficult to recognize voice sounds.

Voice signals have many frequencies, and so do all the other random sounds in the environment. It is generally not possible to reliably distinguish voice from other sounds based on frequency content alone.

To learn more about the difficulty, experiment with audio spectrum visualizing software on a laptop, using the microphone as input.

Free programs to do that, like audacity, are available. This simple real time spectrum analyzer works well on Windows.

when i worked on speakerphones, we compared shorter duration speech levels to background noise level to discern speech. a speaker phone would not work well in an auto-shop with pneumatic tools.

it’s not clear what you intend to so with samples collected at 80Hz or < 40Hz audio (see Nyquist)

As I recall, the human voice is amplitude and frequency modulated. If languages are being spoken, then clicks and whistles are also emitted, depending on the language.
Paul

Thank you very much my friends for your valuable comments
but I have another question
Can you give me some guidance on how robots like Amazon Alexa work? I mean, my question is, for example, when these robots turn on, they store the voice command they receive through the microphone in memory like an SD card and then send it to the speech recognition server, or directly without recording the sound. Does the commanding person send the command to the speech recognition server?

And that's exactly what I want to do; That is, using Arduino or ... I build a circuit in terms of hardware that as soon as it receives a frequency in the human frequency range, it starts recording it (of course, I do not know if it should record my voice command or not) and then send it to the speech recognition server. , Because as far as I know it can be converted to text with our voice command and then processed in the server and inside the server the text is converted into an audio file and then connected to the Arduino by a module like WiFi module and answered inside the Arduino via speaker Play the voice command back

I hope you understand what I mean, my friends

when i worked on speech recognition, we used digital signal processors and codecs designed to sample speech, translate that speech into phoneme models and then run the phonemes across models for specific words. techniques i previously mentioned were used to detect speech and begin the process

i don't believe an microcontroller like an arduino is designed for or capable of sampling speech to the degree necessary to do what you suggest.

Yes, you are right Mr gcjr
But I intend to use Arduino only to record audio and send it to the server and continue the process of speech recognition by the server, which is written in Python, and Arduino only as an intermediary to receive audio from the microphone and then convert the command Return from server to audio via a speaker
I attached a photo of this process below:
https://ibb.co/gMgtmmB

sampling speech is a real-time process that requires periodic sampling which cannot be delayed

speech recognition is a non-real time process and can take as long as it needs or be processed on a server, as you've described

I intend to use Arduino only to record audio and send it to the server and continue the process of speech recognition by the server

Why bother with the Arduino? It is a microcontroller and is not at all useful to record audio.

Use a tool appropriate for the task.

Because this is a project that the university has set for us and we have to use Arduino, thank you if anyone can help me

foxeast:
Because this is a project that the university has set for us and we have to use Arduino, thank you if anyone can help me

Ok, now we know the source. What equipment, such as oscilloscopes, do you have to begin to analyze the sounds you want to study? Is it a recording scope, so you can look at a sound signal over and over until you understand the frequencies that may be there to analyze?
Paul

Post the actual assignment, so that we can help you understand what you are really expected to do.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.