@Anton1863

Как правильно распознать по спикерам аудио-файл в google cloud speech to text?

Пытаюсь распознать тестовый аудиофайл по спикерам (сторонам разговора) через Google Cloud,
просто аудио распознается, а по спикерам не хочет никак, вот кусок кода на php:
<?php
//   # Includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';

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=" . __DIR__ . "/путь до моего json-файла");

$audioFile = __DIR__ . '/test_call.wav';;

$encoding = AudioEncoding::LINEAR16;
$sampleRateHertz = 8000;
$languageCode = 'ru-RU';
$enableSpeakerDiarization = true;
$diarizationSpeakerCount =  2;
$model = 'phone_call';

// get contents of a file into a string
$content = file_get_contents($audioFile);

// set string as audio content
$audio = (new RecognitionAudio())
    ->setContent($content);

// set config
$config = (new RecognitionConfig())
    ->setEncoding($encoding)
    ->setSampleRateHertz($sampleRateHertz)
    ->setLanguageCode($languageCode)
    ->setEnableSeparateRecognitionPerChannel($enableSpeakerDiarization)
    ->setAudioChannelCount($diarizationSpeakerCount)
    ->setModel($model);

// create the speech client
$client = new SpeechClient();
// $client->useApplicationDefaultCredentials();

// create the asyncronous recognize operation
$operation = $client->longRunningRecognize($config, $audio);
$operation->pollUntilComplete();

if ($operation->operationSucceeded()) {
    $response = $operation->getResult();

    // each result is for a consecutive portion of the audio. iterate
    // through them to get the transcripts for the entire audio file.
    foreach ($response->getResults() as $result) {
        $alternatives = $result->getAlternatives();
        $mostLikely = $alternatives[0];
        $transcript = $mostLikely->getTranscript();
        $confidence = $mostLikely->getConfidence();
        $words = $mostLikely->getWords();
        printf('Transcript: %s' . PHP_EOL, $transcript);
        printf('Confidence: %s' . PHP_EOL, $confidence);
        var_dump($words);
        foreach ($words as $wordInfo) {
        	echo 'word: ' . $wordInfo->getWord() . 'speaker_tag: ' . $wordInfo->getSpeakerTag() . "\n\r";
        }
    }

} else {
    print_r($operation->getError());
}

$client->close();


После данного кода корректно отображаются "Transcript" и "Confidence", а в $words вместо массива объектов находится объект "Google\Protobuf\Internal\RepeatedField". Кто может подсказать, в чем затык?
  • Вопрос задан
  • 71 просмотр
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы