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

Is there a built-in way of making asynchronous requests? #113

Closed
NinoSkopac opened this issue May 9, 2018 · 1 comment
Closed

Is there a built-in way of making asynchronous requests? #113

NinoSkopac opened this issue May 9, 2018 · 1 comment
Assignees
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@NinoSkopac
Copy link

👋

Is there a built-in way of issuing multiple concurrent requests (specifically, for TTS)?
My use case is as follows: I want to use TTS to convert text into audio, but since it's a long string I'd like to split it up into chunks of 5000 chars each and convert them concurrently (in order to save time).

In AWS' SDK, I use CommandPool, which makes this very easy (example).

Furrhermore, AWS' SDK will also retry any failed attempts, so all I had to do to implement AWS Polly (their version of TTS) is as follows:

    public function synthesize() : SynthesisInterface {
        $config = Config::getPollyConfig();
        $config += ['retries' => 1000];
        $polly = new PollyClient($config);

        $commandGenerator = function(array $chunks) use ($polly) {
            foreach ($chunks as $chunk) {
                yield $polly->getCommand('SynthesizeSpeech', [
                    'OutputFormat' => Config::Output_Format,
                    'Text' => $chunk,
                    'TextType' => 'text',
                    'VoiceId' => $this->voiceId
                ]);
            }
        };

        $commands = $commandGenerator($this->getTextChunks());
        $pool = new CommandPool($polly, $commands, [
            'concurrency' => 80,
            'fulfilled' => $this->getPollyFulfilledFn(),
            'rejected' => $this->getPollyRejectedFn()
        ]);

        $promise = $pool->promise();
        $promise->wait();
        ksort($this->audio);

        return $this;
    }

Can I do this with your SDK?

@mattwhisenhunt mattwhisenhunt added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label May 10, 2018
@mattwhisenhunt
Copy link

Check out the GCP client for all the latest bells and whistles: https://github.com/GoogleCloudPlatform/google-cloud-php#google-cloud-translation-ga

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

2 participants