我如何使用现场麦克风而不是使用 MP3 播放器 Twilio

问题描述 投票:0回答:0

嗨,我已经使用 laravel 和 twilio 构建了一个应用程序,一切都运行良好,但我想做的是从浏览器与我打电话的电话交谈,而不是播放那首 MP3 歌曲 我该怎么做

语音控制器.php


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Twilio\Exceptions\RestException;
use Twilio\Rest\Client;

class VoiceController extends Controller
{
  public function __construct() {
    // Twilio credentials
    $this->account_sid = env('ACCOUNT_SID');
    $this->auth_token = env('AUTH_TOKEN');
    //the twilio number you purchased
    $this->from = env('TWILIO_PHONE_NUMBER');

    // Initialize the Programmable Voice API
    $this->client = new Client($this->account_sid, $this->auth_token);
  }

  /**
   * Making an outgoing call
   */
  public function initiateCall(Request $request) {
    // Validate form input
    $this->validate($request, [
      'phone_number' => 'required|string',
    ]);

    try {
      //Lookup phone number to make sure it is valid before initiating call
      $phone_number = $this->client->lookups->v1->phoneNumbers($request->phone_number)->fetch();

      // If phone number is valid and exists
      if($phone_number) {
        // Initiate call and record call
        $call = $this->client->account->calls->create(
          $request->phone_number, // Destination phone number
          $this->from, // Valid Twilio phone number
          array(
              "record" => True,
              "url" => "http://demo.twilio.com/docs/voice.xml")
          );

        if($call) {
          echo 'Call initiated successfully';
        } else {
          echo 'Call failed!';
        }
      }
    } catch (Exception $e) {
      echo 'Error: ' . $e->getMessage();
    } catch (RestException $rest) {
      echo 'Error: ' . $rest->getMessage();
    }
  }
}
php laravel twilio voip voice
© www.soinside.com 2019 - 2024. All rights reserved.