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

Doesn't work with OpenAI-PHP lib #231

Open
NinoSkopac opened this issue Sep 7, 2024 · 4 comments
Open

Doesn't work with OpenAI-PHP lib #231

NinoSkopac opened this issue Sep 7, 2024 · 4 comments

Comments

@NinoSkopac
Copy link

<?php
use Spatie\Async\Pool;

require __DIR__ . '/vendor/autoload.php';

$input = [
    "Sentence 1.",
    "Sentence 2."
];
$pool = Pool::create();

$yourApiKey = 'get your own';
$client = OpenAI::client($yourApiKey);

foreach ($input as $index => $text) {
    $pool->add(function () use ($client, $text, $index) {
        $audio = $client->audio()->speech([
            'model' => 'tts-1',
            'input' => $text,
            'voice' => 'alloy',
            'response_format' => 'mp3',
        ]); // audio file content as string

        file_put_contents("output_$index.mp3", $audio);
    });
}

$pool->wait();

errors

Fatal error: Uncaught TypeError: Cannot assign Laravel\SerializableClosure\Serializers\Native to property OpenAI\Transporters\HttpTransporter::$streamHandler of type Closure in /Users/onin/dev/tests/openai/tts/vendor/laravel/serializable-closure/src/Serializers/Native.php:513
Stack trace:
#0 /Users/onin/dev/tests/openai/tts/vendor/laravel/serializable-closure/src/Serializers/Native.php(513): ReflectionProperty->setValue(Object(OpenAI\Transporters\HttpTransporter), Object(Laravel\SerializableClosure\Serializers\Native))
#1 /Users/onin/dev/tests/openai/tts/vendor/laravel/serializable-closure/src/Serializers/Native.php(510): Laravel\SerializableClosure\Serializers\Native->mapByReference(Object(OpenAI\Transporters\HttpTransporter))
#2 /Users/onin/dev/tests/openai/tts/vendor/laravel/serializable-closure/src/Serializers/Native.php(440): Laravel\SerializableClosure\Serializers\Native->mapByReference(Object(OpenAI\Client))
#3 /Users/onin/dev/tests/openai/tts/vendor/laravel/serializable-closure/src/Serializers/Native.php(143): Laravel\SerializableClosure\Serializers\Native->mapByReference(Array)
#4 [internal function]: Laravel\SerializableClosure\Serializers\Native->__serialize()
#5 /Users/onin/dev/tests/openai/tts/vendor/spatie/async/src/Runtime/ParentRuntime.php(88): serialize(Object(Laravel\SerializableClosure\SerializableClosure))
#6 /Users/onin/dev/tests/openai/tts/vendor/spatie/async/src/Runtime/ParentRuntime.php(70): Spatie\Async\Runtime\ParentRuntime::encodeTask(Object(Laravel\SerializableClosure\SerializableClosure), 100000)
#7 /Users/onin/dev/tests/openai/tts/vendor/spatie/async/src/Pool.php(149): Spatie\Async\Runtime\ParentRuntime::createProcess(Object(Closure), NULL, '/opt/homebrew/C...', 100000)
#8 /Users/onin/dev/tests/openai/tts/app.php(17): Spatie\Async\Pool->add(Object(Closure))
#9 {main}
  thrown in /Users/onin/dev/tests/openai/tts/vendor/laravel/serializable-closure/src/Serializers/Native.php on line 513
@rhughes8469
Copy link

Have you found a fix for this? I wasted 2 hours of my life thinking I was screwing something up then found your open issue here.

@NinoSkopac
Copy link
Author

NinoSkopac commented Oct 10, 2024

No. OpenAi's Python lib works fine.

@rhughes8469
Copy link

How is that relevant?

@NinoSkopac
Copy link
Author

It achieves the same solution in a different programming language

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants