src/Api/MessageThread.php
public function sendAudio(string $audioContents, int $audioLengthSeconds) : ?Message
    {
        $data = (object)[
            'messageEventDetail' => (object)[
                'eventCategoryCode' => MessageType::Audio, 
                'messageDetail' => (object)[
                    'body' => '',
                    'voiceDetail' => (object)[
                        'playbackTime' => $audioLengthSeconds
                    ]
                ]
            ]
        ];

        $parameters = 
        [
            [
                'name' => 'messageEventDetail',
                'contents' => json_encode($data, JSON_PRETTY_PRINT),
                'headers' => [
                    'Content-Type' => 'application/json; charset=utf-8'
                ]
            ],
            [
                'name' => 'voiceData',
                'contents' => $audioContents,
                'headers' => [
                    'Content-Type' => 'audio/3gpp',
                    'Content-Transfer-Encoding' => 'binary',
                ]
            ]
        ];

        $response = $this->postMultiPart(sprintf(MessageThread::MESSAGE_THREAD_ENDPOINT . 'threads/%s/messages', $this->messageThreadId), $parameters);

        $messageFields = $this->info(1, true);

        if (!isset($messageFields->threadEvents)) return null;

        $messageData = $messageFields->threadEvents[0];

        return new Message($this->client, $messageData->messageEventDetail, $this);
    }
public function sendAudio(string $audioContents, int $audioLengthSeconds) : ?Message
    {
        $data = (object)[
            'messageEventDetail' => (object)[
                'eventCategoryCode' => MessageType::Audio, 
                'messageDetail' => (object)[
                    'body' => '',
                    'voiceDetail' => (object)[
                        'playbackTime' => $audioLengthSeconds
                    ]
                ]
            ]
        ];

        $parameters = 
        [
            [
                'name' => 'messageEventDetail',
                'contents' => json_encode($data, JSON_PRETTY_PRINT),
                'headers' => [
                    'Content-Type' => 'application/json; charset=utf-8'
                ]
            ],
            [
                'name' => 'voiceData',
                'contents' => $audioContents,
                'headers' => [
                    'Content-Type' => 'audio/3gpp',
                    'Content-Transfer-Encoding' => 'binary',
                ]
            ]
        ];

        $response = $this->postMultiPart(sprintf(MessageThread::MESSAGE_THREAD_ENDPOINT . 'threads/%s/messages', $this->messageThreadId), $parameters);

        $messageFields = $this->info(1, true);

        if (!isset($messageFields->threadEvents)) return null;

        $messageData = $messageFields->threadEvents[0];

        return new Message($this->client, $messageData->messageEventDetail, $this);
    }
public function sendAudio ( string $ audioContents , int $ audioLengthSeconds ) : ? Message { $ data = ( object ) [ 'messageEventDetail' => ( object ) [ 'eventCategoryCode' => MessageType :: Audio , 'messageDetail' => ( object ) [ 'body' => '' , 'voiceDetail' => ( object ) [ 'playbackTime' => $ audioLengthSeconds ] ] ] ] ; $ parameters = [ [ 'name' => 'messageEventDetail' , 'contents' => json_encode ( $ data , JSON_PRETTY_PRINT ) , 'headers' => [ 'Content-Type' => 'application/json; charset=utf-8' ] ] , [ 'name' => 'voiceData' , 'contents' => $ audioContents , 'headers' => [ 'Content-Type' => 'audio/3gpp' , 'Content-Transfer-Encoding' => 'binary' , ] ] ] ; $ response = $ this -> postMultiPart ( sprintf ( MessageThread :: MESSAGE_THREAD_ENDPOINT . 'threads/%s/messages' , $ this -> messageThreadId ) , $ parameters ) ; $ messageFields = $ this -> info ( 1 , true ) ; if ( ! isset ( $ messageFields -> threadEvents ) ) return null ; $ messageData = $ messageFields -> threadEvents [ 0 ] ; return new Message ( $ this -> client , $ messageData -> messageEventDetail , $ this ) ; }
Send an audio message.

@param string $audioContents Raw bytes of the audio.
@param integer $audioLengthSeconds Length of the audio in seconds.
@return Message|null
Send an audio message .