Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TalesFromTheNetworkRoom opened this issue Jul 21, 2024 · 0 comments
Labels
samples Issues that are directly related to samples.

Comments

@TalesFromTheNetworkRoom

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.

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
samples Issues that are directly related to samples.
Projects
None yet
Development

No branches or pull requests

1 participant