PHP code example of qbhy / xfyun

1. Go to this page and download the library: Download qbhy/xfyun library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

qbhy / xfyun example snippets




// laravel 环境下直接注入即可
function(\Qbhy\XFYun\App $xfyun) {
    // todo
}

// hyperf 环境下注入 HyperfXFYun 即可,用法完全一样
function(\Qbhy\XFYun\HyperfXFYun $xfyun) {
    // todo
}

// 其他 php 框架请自行实例化
$xfyun = new Qbhy\XFYun\App([
    'debug' => true,
    'app_id' => 'XFYUN_APP_ID',
    'app_key' => 'XFYUN_APP_KEY',
]);

$result = $xfyun->voice_extension->identifySong('https://xfyun-doc.cn-bj.ufileos.com/1537253485018707/qlzw2.wav');
dump($result);// 识别结果
/**
 array:4 [
  "code" => "0"
  "data" => array:3 [
    0 => array:6 [
      "song" => "千里之外"
      "song_id" => "6433782"
      "singer" => "周杰伦"
      "singer_id" => "313264"
      "start_time" => 24600
      "end_time" => 40490
    ]
    1 => array:6 [
      "song" => "千里之外"
      "song_id" => "6433782"
      "singer" => "周杰伦"
      "singer_id" => "313264"
      "start_time" => 124250
      "end_time" => 137190
    ]
    2 => array:6 [
      "song" => "千里之外"
      "song_id" => "6433782"
      "singer" => "周杰伦"
      "singer_id" => "313264"
      "start_time" => 207800
      "end_time" => 222640
    ]
  ]
  "desc" => "success"
  "sid" => "wbh460b2fb0@gz153a14aa3f18460b00"
]
 */