discord-php / DiscordPHP

An API to interact with the popular messaging app Discord
MIT License
977 stars 236 forks source link

how can i record the voice to disk? #1119

Open KoIIIeY opened 1 year ago

KoIIIeY commented 1 year ago
          $discord->joinVoiceChannel($channel, false, false, null, true)->then(function (VoiceClient $vc) use ($channel, $ffmpeg, 
                $audioOutput)  {
                $vc->playFile(storage_path('44.wav')); // work

                $vc->on('ready', function(...$data) use($vc, $audioOutput){ //never called
                    dump(['ready', $data]);

                    $receiveStream = $vc->getRecieveStream(272445599360614401);
                    dump(['receive stream', $receiveStream?->isReadable()]);

                    $dest = new \React\Stream\WritableResourceStream(fopen($audioOutput, 'a'));
                    $receiveStream?->pipeOpus($dest);

                    echo "Stream recorded.", PHP_EOL;
                });

                $vc->on('channel-opus', function(...$data) use($audioOutput){ //never called
                    dump(['speak', $data]);

                });

                $vc->on('channel-pcm', function(...$data) use($audioOutput){ //never called
                    dump(['speak', $data]);
                });

            },function ($err){ dump($err); });

Can someone write an example of recording voice to disk?

SQKo commented 1 year ago

The voice receive is non functioning, this part of code is unfinished since there is no official documentation to implement it.