□■□ Home | Login | GTP | Bard | bing | fastDemo | Usage | ana | ads | sc | WEBPUSH |
一覧

処理方法

FormでURLを入力する
-> URLをSSHで変換PCに転送
ssh user@pc "command url"

受け取ったコマンドで yt-dlpとffmpegで音声ファイルを作成する
① このPCでそのまま whisper APIを起動して、resultだけ返す
② 音声ファイルを転送して formPCに返す

Whisper API for PHP

composer内のAPI
// remove this line if you use a PHP Framework. 
require_once __DIR__ . '/vendor/autoload.php'; 

// Import the OpenAI class from the SDK 
use Orhanerday\OpenAi\OpenAi; 
// Set the path to the audio file to transcribe 
$audioFile = 'path/to/audio.mp3'; 
// Create a CURL file object for the audio file 
$cFile = curl_file_create($audioFile, 'audio.mp3'); 

// Use transcription 
$response_text = $open_ai->transcribe([ "model" => "whisper-1", "file" => $cFile, ]); 
var_dump($response_text); 

// Use translation 
$reply_vtt = $open_ai->translate([ "model" => "whisper-1", "file" => $cFile, "response_format" => 'vtt', ]); 
var_dump($reply_vtt);

Curl
$apikey = "sk-APIKEY";
$url = "https://api.openai.com/v1/chat/completions";

// リクエストヘッダー
$headers = array(
  'Content-Type: application/json',
  'Authorization: Bearer ' . $apikey
);

// リクエストボディ
$data = array(
  'model' => 'gpt-3.5-turbo',
  'messages' => [
      ["role" => "system", "content" => "関西弁で話して"],
      ['role' => 'user', 'content' => "ここに質問文を書きます")],
  ],
  'max_tokens' => 500,
);

// cURLを使用してAPIにリクエストを送信 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 

$response = curl_exec($ch); 
curl_close($ch); 

// 結果をデコード
$result = json_decode($response, true);
$result_message = $result["choices"][0]["message"]["content"];

// 結果を出力 
echo $result_message;