Google-cloud-php: Please add support for all options on RecognitionConfig

Created on 9 Jul 2019  路  8Comments  路  Source: googleapis/google-cloud-php

Copied from https://github.com/googleapis/google-api-php-client-services/issues/173


When you are creating the RecognitionConfig object there are no methods to set the following properties which could improve our transcription results.

RecognitionMetadata
SpeakerDiarizationConfig
SpeechContext

speech question

All 8 comments

@paulsheldrake, are you using the latest version of google/cloud-speech? RecognitionConfig is accepted as an argument to SpeechClient::recognize() and SpeechClient::longRunningRecognize() and allows use of RecognitionMetadata by calling RecognitionConfig::setMetadata(), and SpeechContext by calling setSpeechContexts().

I do not see any definition in the API for SpeakerDiarizationConfig. Can you provide additional information?

Hello, thanks for getting back to me. I am using the latest version of the library "google/cloud": "^0.105.0"

For the SpeakerDiarizationConfig question I've realized I was looking at the wrong documentation. It's an option in the v1p1beta1 version. Sorry about that.
https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionConfig#SpeakerDiarizationConfig

Do you have an example somewhere of RecognitionConfig::setMetadata()? Something in the vein of https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/speech/src/transcribe_async_gcs.php

I'm getting these errors
Deprecated function: Non-static methodGoogle\Cloud\Speech\V1\RecognitionConfig::setMetadata()

Sure, try something like this:

use Google\Cloud\Speech\V1\RecognitionAudio;
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\RecognitionMetadata;
use Google\Cloud\Speech\V1\SpeechClient;

$content = file_get_contents($audioFile);

$audio = new RecognitionAudio();
$audio->setContent($content);

$metadata = new RecognitionMetadata;

// Provide to the constructor
$config = new RecognitionConfig([
    'metadata' => $metadata
]);

// Or using the setter
$config->setMetadata($metadata);

$client = new SpeechClient();
$response = $client->recognize($config, $audio);

I'll look into the SpeakerDiarizationConfig question.

This is great, thank you!

Despite being documented, the SpeakerDiarizationConfig type is not yet available in the API definitions. We'll ask the API team about this, and I expect that it will become available before too long.

@paulsheldrake, FYI, #2126 was just merged, adding support for SpeakerDiarizationConfig. It'll be included in the next release. :)

Thanks for the heads up!

Hello,

I am trying to add the SpeakerDiarizationConfig to the RecognitionConfig but I am not able to do that and I don't see any example on the documentation page in order to make it work. Could you please @jdpedrie or @paulsheldrake help me to achieve this? My approach is the following:

diarization_config = {
"enableSpeakerDiarization": True,
"minSpeakerCount": 2,
"maxSpeakerCount": 3}
config = types.RecognitionConfig(
encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,
sample_rate_hertz=frame_rate,
language_code="es-ES",
enable_word_time_offsets=True,
diarization_config=diarization_config,
enable_automatic_punctuation=True)

Thanks in advance!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

castaneai picture castaneai  路  7Comments

smalot picture smalot  路  6Comments

highstrike picture highstrike  路  5Comments

LoekvanKooten picture LoekvanKooten  路  6Comments

Google-K picture Google-K  路  6Comments