I am making an audio filtering application at work that reads over hundreds of audio files and filters them. So, if the audio has human voice in it, it will accept it and if it does not- it will delete the audio file.
I am using ffmpeg to get the details of the audio and add other filters like size and duration and silence (though it is not very accurate in detecting silence for all audio files.)
My company asked me to try the Google Cloud Speech API to detect if the audio has any human voice in it.
So with this code, some audio files return a Transcript of spoken words in the audio file, but what I need is to determine if a human is speaking or not.
I have considered using hark.js for it but there does not seem to be enough documentation and I am short on time!
Ps. I am an intern and I'm just starting out with programming. I apologize if my question does not make sense or sounds dumb.
# Includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';
# Imports the Google Cloud client library
use Google\Cloud\Speech\V1\SpeechClient;
use Google\Cloud\Speech\V1\RecognitionAudio;
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;
putenv('GOOGLE_APPLICATION_CREDENTIALS=../../credentials.json');
echo getcwd() . "<br>";
chdir('test-sounds');
echo getcwd() . "<br>";
echo shell_exec('ls -lr');
$fileList = glob('*');
foreach($fileList as $filename){
//echo $filename, '<br>';
# The name of the audio file to transcribe
$audioFile = __DIR__ . '/' . $filename;
# get contents of a file into a string
$content = file_get_contents($audioFile);
# set string as audio content
$audio = (new RecognitionAudio())
->setContent($content);
# The audio file's encoding, sample rate and language
$config = new RecognitionConfig([
'encoding' => AudioEncoding::LINEAR16,
'language_code' => 'ja-JP'
]);
# Instantiates a client
$client = new SpeechClient();
# Detects speech in the audio file
$response = $client->recognize($config, $audio);
# Print most likely transcription
foreach ($response->getResults() as $result) {
$alternatives = $result->getAlternatives();
$mostLikely = $alternatives[0];
$transcript = $mostLikely->getTranscript();
printf('<br>Transcript: %s' . PHP_EOL, $transcript . '<br>');
}
$client->close();
}
?> ```