这是indexloc提供的服务,不要输入任何密码
Skip to content

Can't find examples for TranscriptOutputConfig or how retrieve async operations #2035

@TalesFromTheNetworkRoom

Description

Good morning,
I'm currently writing a small php program with a web interface to allow my client to transcribe lenghty audio records.

1.I succesfully applied the function transcribe_async_gcs and tested it.
I was looking at this page "Method: speech.longrunningrecognize" the section which describe:

"outputConfig": {
object ([TranscriptOutputConfig])
}

object ([TranscriptOutputConfig])

Optional. Specifies an optional destination for the recognition results.

But for the love of my sanity I couldn't find any apllicable example for php.
Looking inside the speech to text package I found some uses for this object so I tried to write something like this:

use Google\Cloud\Speech\V1\TranscriptOutputConfig;

    // set output bucket
    $output = (new TranscriptOutputConfig())
        ->setGcsUri('gs://my_bucket/'.$fileName.'.txt');

and then: $operation = $client->longRunningRecognize($config, $audio, [$output]); -> output as array
But to no success, it didn't produce any text file in my bucket.
What am I missing? If there are any examples or documentation that I did not find could you please point me to it? Thanks.

  1. The second problem is related to the time to process the file, looking at the function transcribe_async_gcs:

// 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();
        printf('Transcript: %s' . PHP_EOL, $transcript);
        printf('Confidence: %s' . PHP_EOL, $confidence);
    }
} else {
    print_r($operation->getError());
}

$client->close();

$operation->pollUntilComplete(); --> this part does not run async, it makes my controller wait for the function be finished.
I found this old thread on stack that goes like this:
(https://stackoverflow.com/questions/55316150/how-to-resume-google-cloud-speech-api-longrunningrecognize-timeout-on-cloud-fu)

$operationName = $operation->getName(); -> gets operation name, I manage to get this to work with mine as well.

then in a separate controller:

CloudSpeech::initOnce();
$newOperationResponse = $speechClient->resumeOperation($name, 'LongRunningRecognize');

if ($newOperationResponse->operationSucceeded()) {
$result = $newOperationResponse->getResult();

}

But it doesn't work with mine, I get thi error:

Error occurred during parsing: Class google.cloud.speech.v1.LongRunningRecognizeMetadata hasn't been added to descriptor pool.

I think I need to add somenthing but then again, there are no examples so I'm stuck at this point.
Sorry I posted such a lengthy question, but I'm getting desperated a this point.
Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    samplesIssues that are directly related to samples.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions