├── upload_tmp └── 1 ├── audio_result └── 1 ├── .env.example ├── .gitignore ├── clean.php ├── system ├── inc.php ├── Url.php ├── function.php └── OpenAi.php ├── README.md ├── README.en.md ├── LICENSE ├── chat.php ├── index.php └── recorder.mp3.min.js /upload_tmp/1: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /audio_result/1: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | API_URL = https://api.openai.com/ 2 | API_KEY = sk-xxx -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # 忽略.vscode文件夹 2 | .vscode/ 3 | .env 4 | .gitignore 5 | .envbackup -------------------------------------------------------------------------------- /clean.php: -------------------------------------------------------------------------------- 1 | setBaseURL($conf['API_URL']); 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [English README](README.en.md) 2 | 3 | # 项目简介 4 | 5 | 这个项目是一个简单的 demo,它使用了 TTS-1、Whisper 和 GPT-3.5-turbo 来进行对话交互。 6 | 7 | ## 技术栈 8 | 9 | - 前端使用 `bootstarp`、`vue2` 和 `recorder` 进行构建。 10 | - 前台支持选择浏览器语音转文字(低延迟)或者调用 OpenAI 的 Whisper(高精度)。 11 | - 前台可以上传 `mp3` 格式文件到 PHP,通过调用 TTS 得到 `opus` 音频以保证效率。 12 | - 访问 `clean.php` 可以清理缓存文件。 13 | 14 | ## 修改与更新 15 | 16 | - 去除了 Composer 依赖,改为内置修改版的 [OpenAI 库](https://github.com/orhanerday/open-ai),同时加入了与 TTS 相关的函数。 17 | - 现在使用自定义简单函数获取 `.env` 变量。 18 | 19 | # 部署教程 20 | 21 | 为了最佳效果,推荐使用 PHP 8.1。 22 | 23 | 1. `.env.example` 修改为 `.env`,并配置其中的 OpenAI Key 和 URL(如果需要使用代理,则修改 URL)。 24 | 25 | 2.必须使用https否则无法录音 -------------------------------------------------------------------------------- /README.en.md: -------------------------------------------------------------------------------- 1 | # Project Introduction 2 | 3 | This project is a simple demo that utilizes TTS-1, Whisper, and GPT-3.5-turbo for conversational interactions. 4 | 5 | ## Technology Stack 6 | 7 | - The front end is built using `bootstarp`, `vue2`, and `recorder`. 8 | - The front end supports selecting browser-based speech-to-text (low latency) or calling OpenAI's Whisper (high accuracy). 9 | - Users can upload `mp3` format files to PHP and obtain `opus` audio through TTS to ensure efficiency. 10 | - Accessing `clean.php` allows for the clearing of cache files. 11 | 12 | ## Modifications and Updates 13 | 14 | - Removed Composer dependencies, and instead integrated a modified version of the [OpenAI library](https://github.com/orhanerday/open-ai), incorporating functions related to TTS. 15 | - Now utilizes a custom simple function to retrieve `.env` variables. 16 | 17 | # Deployment Guide 18 | 19 | For optimal performance, it is recommended to use PHP 8.1. 20 | 21 | 1. Rename `.env.example` to `.env` and configure the OpenAI Key and URL inside it (modify the URL if a proxy is required). 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 xy3xy3 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /chat.php: -------------------------------------------------------------------------------- 1 | $ai_msg]); 21 | } elseif ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['audio'])) { 22 | $audioFile = $_FILES['audio']; 23 | $tempFilePath = $audioFile['tmp_name']; 24 | $tmpfile = __DIR__ . "/upload_tmp/" . md5($tempFilePath) . ".mp3"; 25 | copy($tempFilePath, $tmpfile); 26 | // 语音转文字 27 | $text = audioTotext($tmpfile); 28 | if (empty($text)) { 29 | json("语音转文字失败"); 30 | } 31 | // 获取chat对话 32 | $ai_msg = chat($text); 33 | if (empty($ai_msg)) { 34 | json("ai回答失败"); 35 | } 36 | $audioData = speech($ai_msg, $_POST['voice']); 37 | if (empty($audioData)) { 38 | json("ai回答失败"); 39 | } 40 | //保存.wav到save 41 | $dir = '/audio_result/' . md5($ai_msg) . ".opus"; 42 | $saveDirectory = __DIR__ . $dir; 43 | file_put_contents($saveDirectory, $audioData); 44 | json($dir, 0, ['ai_msg' => $ai_msg]); 45 | } else { 46 | json("没收到文件且没有文本"); 47 | } 48 | -------------------------------------------------------------------------------- /system/Url.php: -------------------------------------------------------------------------------- 1 | $code, 'msg' => $msg]; 5 | //合并extra和data 6 | $data = array_merge($data, $extra); 7 | echo json_encode($data); 8 | exit(); 9 | } 10 | function audioTotext($c_file) 11 | { 12 | global $open_ai; 13 | $c_file = curl_file_create($c_file); 14 | $result = $open_ai->transcribe([ 15 | "model" => "whisper-1", 16 | "file" => $c_file, 17 | ]); 18 | $d = json_decode($result, true); 19 | // if (!isset($d["text"])) { 20 | // print_r($result); 21 | // } 22 | return isset($d["text"]) ? $d["text"] : null; 23 | } 24 | function speech($text, $voice) 25 | { 26 | global $open_ai; 27 | if (empty($voice)) $voice = "echo"; 28 | $result = $open_ai->speech([ 29 | "model" => "tts-1", 30 | "input" => $text, 31 | "voice" => $voice, 32 | "response_format" => "opus" 33 | ]); 34 | return $result; 35 | } 36 | function chat($text) 37 | { 38 | global $open_ai; 39 | $memory_entry = [ 40 | "role" => "user", 41 | "content" => $text 42 | ]; 43 | // 加入记忆 44 | if (isset($_SESSION['memory'])) { 45 | $tmp = $_SESSION['memory']; 46 | } else { 47 | $tmp = []; 48 | } 49 | $tmp[] = $memory_entry; 50 | $arr = [ 51 | 'model' => 'gpt-3.5-turbo-1106', 52 | 'messages' => $tmp, 53 | 'temperature' => 0.7, 54 | 'max_tokens' => 1000, 55 | ]; 56 | $complete = $open_ai->chat($arr); 57 | $d = json_decode($complete, true); 58 | if (isset($d['choices'][0]['message']['content'])) { 59 | $ai_msg = $d['choices'][0]['message']['content']; 60 | memory($text, $ai_msg); 61 | return $ai_msg; 62 | } else { 63 | // print_r($complete); 64 | return null; 65 | } 66 | } 67 | function memory($u, $a) 68 | { 69 | if (empty($u) || empty($a)) return; 70 | // 初始化或检查是否已经存在 $_SESSION['memory'] 71 | if (isset($_SESSION['memory'])) { 72 | // 只取最后的6对(如果有),然后加入新的 73 | $_SESSION['memory'][] = [ 74 | "role" => "user", 75 | "content" => $u 76 | ]; 77 | $_SESSION['memory'][] = [ 78 | "role" => "assistant", 79 | "content" => $a 80 | ]; 81 | // 截取最后的6对 82 | $_SESSION['memory'] = array_slice($_SESSION['memory'], -6); 83 | } else { 84 | // 如果 $_SESSION['memory'] 不存在,创建并添加第一对对话 85 | $_SESSION['memory'] = [ 86 | [ 87 | "role" => "user", 88 | "content" => $u 89 | ], 90 | [ 91 | "role" => "assistant", 92 | "content" => $a 93 | ] 94 | ]; 95 | } 96 | } 97 | function deleteDirectory($dir) 98 | { 99 | if (!file_exists($dir)) { 100 | return true; 101 | } 102 | 103 | if (!is_dir($dir)) { 104 | return unlink($dir); 105 | } 106 | 107 | foreach (scandir($dir) as $item) { 108 | if ($item == '.' || $item == '..') { 109 | continue; 110 | } 111 | 112 | if (!deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) { 113 | return false; 114 | } 115 | } 116 | } 117 | function loadEnvVariables($filePath) 118 | { 119 | $variables = array(); 120 | 121 | if (file_exists($filePath)) { 122 | $file = fopen($filePath, 'r'); 123 | 124 | while (($line = fgets($file)) !== false) { 125 | $line = trim($line); 126 | 127 | // 跳过以#开头的注释行和空行 128 | if (empty($line) || $line[0] === '#') { 129 | continue; 130 | } 131 | 132 | // 解析变量名和值 133 | $parts = explode('=', $line, 2); 134 | $name = trim($parts[0]); 135 | $value = isset($parts[1]) ? trim($parts[1]) : ''; 136 | 137 | // 移除变量值中的引号 138 | if (preg_match('/^"(.+)"$/', $value, $matches) === 1) { 139 | $value = $matches[1]; 140 | } 141 | 142 | $variables[$name] = $value; 143 | } 144 | 145 | fclose($file); 146 | } 147 | 148 | return $variables; 149 | } 150 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | AI语音对话 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 31 | 32 | 33 | 34 |
35 |
36 |
37 |
38 |
39 |
语音对话chatgpt
40 |
41 |
42 | 加载中... 43 |
44 | 需要一些时间进行思考 45 |
46 | 47 |
48 |
49 | 加载中... 50 |
51 | 说话中 52 |
53 |
54 |
55 |
56 | 57 | 58 |
59 |
60 |
61 | 62 | 66 |
67 |
68 | 69 | 74 |
75 |
76 | 77 | 85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 | 98 | 99 | 100 | 278 | 279 | 280 | -------------------------------------------------------------------------------- /system/OpenAi.php: -------------------------------------------------------------------------------- 1 | contentTypes = [ 18 | "application/json" => "Content-Type: application/json", 19 | "multipart/form-data" => "Content-Type: multipart/form-data", 20 | ]; 21 | 22 | $this->headers = [ 23 | $this->contentTypes["application/json"], 24 | "Authorization: Bearer $OPENAI_API_KEY", 25 | ]; 26 | } 27 | 28 | /** 29 | * @return array 30 | * Remove this method from your code before deploying 31 | */ 32 | public function getCURLInfo() 33 | { 34 | return $this->curlInfo; 35 | } 36 | 37 | /** 38 | * @return bool|string 39 | */ 40 | public function listModels() 41 | { 42 | $url = Url::fineTuneModel(); 43 | $this->baseUrl($url); 44 | 45 | return $this->sendRequest($url, 'GET'); 46 | } 47 | 48 | /** 49 | * @param $model 50 | * @return bool|string 51 | */ 52 | public function retrieveModel($model) 53 | { 54 | $model = "/$model"; 55 | $url = Url::fineTuneModel().$model; 56 | $this->baseUrl($url); 57 | 58 | return $this->sendRequest($url, 'GET'); 59 | } 60 | 61 | /** 62 | * @param $opts 63 | * @return bool|string 64 | * @deprecated 65 | */ 66 | public function complete($opts) 67 | { 68 | $engine = $opts['engine'] ?? $this->engine; 69 | $url = Url::completionURL($engine); 70 | unset($opts['engine']); 71 | $this->baseUrl($url); 72 | 73 | return $this->sendRequest($url, 'POST', $opts); 74 | } 75 | 76 | /** 77 | * @param $opts 78 | * @param null $stream 79 | * @return bool|string 80 | * @throws Exception 81 | */ 82 | public function completion($opts, $stream = null) 83 | { 84 | if (array_key_exists('stream', $opts) && $opts['stream']) { 85 | if ($stream == null) { 86 | throw new Exception( 87 | 'Please provide a stream function. Check https://github.com/orhanerday/open-ai#stream-example for an example.' 88 | ); 89 | } 90 | 91 | $this->stream_method = $stream; 92 | } 93 | 94 | $opts['model'] = $opts['model'] ?? $this->model; 95 | $url = Url::completionsURL(); 96 | $this->baseUrl($url); 97 | 98 | return $this->sendRequest($url, 'POST', $opts); 99 | } 100 | 101 | /** 102 | * @param $opts 103 | * @return bool|string 104 | */ 105 | public function createEdit($opts) 106 | { 107 | $url = Url::editsUrl(); 108 | $this->baseUrl($url); 109 | 110 | return $this->sendRequest($url, 'POST', $opts); 111 | } 112 | 113 | /** 114 | * @param $opts 115 | * @return bool|string 116 | */ 117 | public function image($opts) 118 | { 119 | $url = Url::imageUrl()."/generations"; 120 | $this->baseUrl($url); 121 | 122 | return $this->sendRequest($url, 'POST', $opts); 123 | } 124 | 125 | /** 126 | * @param $opts 127 | * @return bool|string 128 | */ 129 | public function imageEdit($opts) 130 | { 131 | $url = Url::imageUrl()."/edits"; 132 | $this->baseUrl($url); 133 | 134 | return $this->sendRequest($url, 'POST', $opts); 135 | } 136 | 137 | /** 138 | * @param $opts 139 | * @return bool|string 140 | */ 141 | public function createImageVariation($opts) 142 | { 143 | $url = Url::imageUrl()."/variations"; 144 | $this->baseUrl($url); 145 | 146 | return $this->sendRequest($url, 'POST', $opts); 147 | } 148 | 149 | /** 150 | * @param $opts 151 | * @return bool|string 152 | * @deprecated 153 | */ 154 | public function search($opts) 155 | { 156 | $engine = $opts['engine'] ?? $this->engine; 157 | $url = Url::searchURL($engine); 158 | unset($opts['engine']); 159 | $this->baseUrl($url); 160 | 161 | return $this->sendRequest($url, 'POST', $opts); 162 | } 163 | 164 | /** 165 | * @param $opts 166 | * @return bool|string 167 | * @deprecated 168 | */ 169 | public function answer($opts) 170 | { 171 | $url = Url::answersUrl(); 172 | $this->baseUrl($url); 173 | 174 | return $this->sendRequest($url, 'POST', $opts); 175 | } 176 | 177 | /** 178 | * @param $opts 179 | * @return bool|string 180 | * @deprecated 181 | */ 182 | public function classification($opts) 183 | { 184 | $url = Url::classificationsUrl(); 185 | $this->baseUrl($url); 186 | 187 | return $this->sendRequest($url, 'POST', $opts); 188 | } 189 | 190 | /** 191 | * @param $opts 192 | * @return bool|string 193 | */ 194 | public function moderation($opts) 195 | { 196 | $url = Url::moderationUrl(); 197 | $this->baseUrl($url); 198 | 199 | return $this->sendRequest($url, 'POST', $opts); 200 | } 201 | 202 | /** 203 | * @param $opts 204 | * @param null $stream 205 | * @return bool|string 206 | * @throws Exception 207 | */ 208 | public function chat($opts, $stream = null) 209 | { 210 | if ($stream != null && array_key_exists('stream', $opts)) { 211 | if (!$opts['stream']) { 212 | throw new Exception( 213 | 'Please provide a stream function. Check https://github.com/orhanerday/open-ai#stream-example for an example.' 214 | ); 215 | } 216 | 217 | $this->stream_method = $stream; 218 | } 219 | 220 | $opts['model'] = $opts['model'] ?? $this->chatModel; 221 | $url = Url::chatUrl(); 222 | $this->baseUrl($url); 223 | 224 | return $this->sendRequest($url, 'POST', $opts); 225 | } 226 | 227 | public function speech($opts) 228 | { 229 | $url = Url::speechUrl(); 230 | $this->baseUrl($url); 231 | 232 | return $this->sendRequest($url, 'POST', $opts); 233 | } 234 | /** 235 | * @param $opts 236 | * @return bool|string 237 | */ 238 | public function transcribe($opts) 239 | { 240 | $url = Url::transcriptionsUrl(); 241 | $this->baseUrl($url); 242 | 243 | return $this->sendRequest($url, 'POST', $opts); 244 | } 245 | 246 | /** 247 | * @param $opts 248 | * @return bool|string 249 | */ 250 | public function translate($opts) 251 | { 252 | $url = Url::translationsUrl(); 253 | $this->baseUrl($url); 254 | 255 | return $this->sendRequest($url, 'POST', $opts); 256 | } 257 | 258 | /** 259 | * @param $opts 260 | * @return bool|string 261 | */ 262 | public function uploadFile($opts) 263 | { 264 | $url = Url::filesUrl(); 265 | $this->baseUrl($url); 266 | 267 | return $this->sendRequest($url, 'POST', $opts); 268 | } 269 | 270 | /** 271 | * @return bool|string 272 | */ 273 | public function listFiles() 274 | { 275 | $url = Url::filesUrl(); 276 | $this->baseUrl($url); 277 | 278 | return $this->sendRequest($url, 'GET'); 279 | } 280 | 281 | /** 282 | * @param $file_id 283 | * @return bool|string 284 | */ 285 | public function retrieveFile($file_id) 286 | { 287 | $file_id = "/$file_id"; 288 | $url = Url::filesUrl().$file_id; 289 | $this->baseUrl($url); 290 | 291 | return $this->sendRequest($url, 'GET'); 292 | } 293 | 294 | /** 295 | * @param $file_id 296 | * @return bool|string 297 | */ 298 | public function retrieveFileContent($file_id) 299 | { 300 | $file_id = "/$file_id/content"; 301 | $url = Url::filesUrl().$file_id; 302 | $this->baseUrl($url); 303 | 304 | return $this->sendRequest($url, 'GET'); 305 | } 306 | 307 | /** 308 | * @param $file_id 309 | * @return bool|string 310 | */ 311 | public function deleteFile($file_id) 312 | { 313 | $file_id = "/$file_id"; 314 | $url = Url::filesUrl().$file_id; 315 | $this->baseUrl($url); 316 | 317 | return $this->sendRequest($url, 'DELETE'); 318 | } 319 | 320 | /** 321 | * @param $opts 322 | * @return bool|string 323 | */ 324 | public function createFineTune($opts) 325 | { 326 | $url = Url::fineTuneUrl(); 327 | $this->baseUrl($url); 328 | 329 | return $this->sendRequest($url, 'POST', $opts); 330 | } 331 | 332 | /** 333 | * @return bool|string 334 | */ 335 | public function listFineTunes() 336 | { 337 | $url = Url::fineTuneUrl(); 338 | $this->baseUrl($url); 339 | 340 | return $this->sendRequest($url, 'GET'); 341 | } 342 | 343 | /** 344 | * @param $fine_tune_id 345 | * @return bool|string 346 | */ 347 | public function retrieveFineTune($fine_tune_id) 348 | { 349 | $fine_tune_id = "/$fine_tune_id"; 350 | $url = Url::fineTuneUrl().$fine_tune_id; 351 | $this->baseUrl($url); 352 | 353 | return $this->sendRequest($url, 'GET'); 354 | } 355 | 356 | /** 357 | * @param $fine_tune_id 358 | * @return bool|string 359 | */ 360 | public function cancelFineTune($fine_tune_id) 361 | { 362 | $fine_tune_id = "/$fine_tune_id/cancel"; 363 | $url = Url::fineTuneUrl().$fine_tune_id; 364 | $this->baseUrl($url); 365 | 366 | return $this->sendRequest($url, 'POST'); 367 | } 368 | 369 | /** 370 | * @param $fine_tune_id 371 | * @return bool|string 372 | */ 373 | public function listFineTuneEvents($fine_tune_id) 374 | { 375 | $fine_tune_id = "/$fine_tune_id/events"; 376 | $url = Url::fineTuneUrl().$fine_tune_id; 377 | $this->baseUrl($url); 378 | 379 | return $this->sendRequest($url, 'GET'); 380 | } 381 | 382 | /** 383 | * @param $fine_tune_id 384 | * @return bool|string 385 | */ 386 | public function deleteFineTune($fine_tune_id) 387 | { 388 | $fine_tune_id = "/$fine_tune_id"; 389 | $url = Url::fineTuneModel().$fine_tune_id; 390 | $this->baseUrl($url); 391 | 392 | return $this->sendRequest($url, 'DELETE'); 393 | } 394 | 395 | /** 396 | * @param 397 | * @return bool|string 398 | * @deprecated 399 | */ 400 | public function engines() 401 | { 402 | $url = Url::enginesUrl(); 403 | $this->baseUrl($url); 404 | 405 | return $this->sendRequest($url, 'GET'); 406 | } 407 | 408 | /** 409 | * @param $engine 410 | * @return bool|string 411 | * @deprecated 412 | */ 413 | public function engine($engine) 414 | { 415 | $url = Url::engineUrl($engine); 416 | $this->baseUrl($url); 417 | 418 | return $this->sendRequest($url, 'GET'); 419 | } 420 | 421 | /** 422 | * @param $opts 423 | * @return bool|string 424 | */ 425 | public function embeddings($opts) 426 | { 427 | $url = Url::embeddings(); 428 | $this->baseUrl($url); 429 | 430 | return $this->sendRequest($url, 'POST', $opts); 431 | } 432 | 433 | /** 434 | * @param int $timeout 435 | */ 436 | public function setTimeout(int $timeout) 437 | { 438 | $this->timeout = $timeout; 439 | } 440 | 441 | /** 442 | * @param string $proxy 443 | */ 444 | public function setProxy(string $proxy) 445 | { 446 | if ($proxy && strpos($proxy, '://') === false) { 447 | $proxy = 'https://'.$proxy; 448 | } 449 | $this->proxy = $proxy; 450 | } 451 | 452 | /** 453 | * @param string $customUrl 454 | * @deprecated 455 | */ 456 | 457 | /** 458 | * @param string $customUrl 459 | * @return void 460 | */ 461 | public function setCustomURL(string $customUrl) 462 | { 463 | if ($customUrl != "") { 464 | $this->customUrl = $customUrl; 465 | } 466 | } 467 | 468 | /** 469 | * @param string $customUrl 470 | * @return void 471 | */ 472 | public function setBaseURL(string $customUrl) 473 | { 474 | if ($customUrl != '') { 475 | $this->customUrl = $customUrl; 476 | } 477 | } 478 | 479 | /** 480 | * @param array $header 481 | * @return void 482 | */ 483 | public function setHeader(array $header) 484 | { 485 | if ($header) { 486 | foreach ($header as $key => $value) { 487 | $this->headers[$key] = $value; 488 | } 489 | } 490 | } 491 | 492 | /** 493 | * @param string $org 494 | */ 495 | public function setORG(string $org) 496 | { 497 | if ($org != "") { 498 | $this->headers[] = "OpenAI-Organization: $org"; 499 | } 500 | } 501 | 502 | /** 503 | * @param string $url 504 | * @param string $method 505 | * @param array $opts 506 | * @return bool|string 507 | */ 508 | private function sendRequest(string $url, string $method, array $opts = []) 509 | { 510 | $post_fields = json_encode($opts); 511 | 512 | if (array_key_exists('file', $opts) || array_key_exists('image', $opts)) { 513 | $this->headers[0] = $this->contentTypes["multipart/form-data"]; 514 | $post_fields = $opts; 515 | } else { 516 | $this->headers[0] = $this->contentTypes["application/json"]; 517 | } 518 | $curl_info = [ 519 | CURLOPT_URL => $url, 520 | CURLOPT_RETURNTRANSFER => true, 521 | CURLOPT_ENCODING => '', 522 | CURLOPT_MAXREDIRS => 10, 523 | CURLOPT_TIMEOUT => $this->timeout, 524 | CURLOPT_FOLLOWLOCATION => true, 525 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 526 | CURLOPT_CUSTOMREQUEST => $method, 527 | CURLOPT_POSTFIELDS => $post_fields, 528 | CURLOPT_HTTPHEADER => $this->headers, 529 | ]; 530 | 531 | if ($opts == []) { 532 | unset($curl_info[CURLOPT_POSTFIELDS]); 533 | } 534 | 535 | if (!empty($this->proxy)) { 536 | $curl_info[CURLOPT_PROXY] = $this->proxy; 537 | } 538 | 539 | if (array_key_exists('stream', $opts) && $opts['stream']) { 540 | $curl_info[CURLOPT_WRITEFUNCTION] = $this->stream_method; 541 | } 542 | 543 | $curl = curl_init(); 544 | 545 | curl_setopt_array($curl, $curl_info); 546 | $response = curl_exec($curl); 547 | 548 | $info = curl_getinfo($curl); 549 | $this->curlInfo = $info; 550 | 551 | curl_close($curl); 552 | 553 | if (!$response) throw new Exception(curl_error($curl)); 554 | 555 | return $response; 556 | } 557 | 558 | /** 559 | * @param string $url 560 | */ 561 | private function baseUrl(string &$url) 562 | { 563 | if ($this->customUrl != "") { 564 | $url = str_replace(Url::ORIGIN, $this->customUrl, $url); 565 | } 566 | } 567 | } 568 | -------------------------------------------------------------------------------- /recorder.mp3.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | 录音 3 | https://github.com/xiangyuecn/Recorder 4 | src: recorder-core.js,engine/mp3.js,engine/mp3-engine.js 5 | */ 6 | !function(k){"use strict";var S=function(){},O=function(e){return new t(e)};O.LM="2023-07-01 20:46";var x="Recorder",M="getUserMedia",V="srcSampleRate",N="sampleRate",y="catch";O.IsOpen=function(){var e=O.Stream;if(e){var t=e.getTracks&&e.getTracks()||e.audioTracks||[],a=t[0];if(a){var s=a.readyState;return"live"==s||s==a.LIVE}}return!1},O.BufferSize=4096,O.Destroy=function(){for(var e in C(x+" Destroy"),A(),a)a[e]()};var a={};O.BindDestroy=function(e,t){a[e]=t},O.Support=function(){var e=navigator.mediaDevices||{};return e[M]||(e=navigator)[M]||(e[M]=e.webkitGetUserMedia||e.mozGetUserMedia||e.msGetUserMedia),!!e[M]&&(O.Scope=e,!!O.GetContext())},O.GetContext=function(e){var t=k.AudioContext;if(t||(t=k.webkitAudioContext),!t)return null;var a=O.Ctx;if(a&&"closed"!=a.state||(a=O.Ctx=new t,O.NewCtxs=O.NewCtxs||[],O.BindDestroy("Ctx",function(){var e=O.Ctx;e&&e.close&&(e.close(),O.Ctx=0);var t=O.NewCtxs;O.NewCtxs=[];for(var a=0;a"+u,3);for(var m=0,p=i;p"+v.length+" 花:"+(Date.now()-s)+"ms"),setTimeout(function(){s=Date.now(),n[r.type](v,function(e){f(e,p)},function(e){l(e)})})}else l("未加载"+r.type+"编码器");else l("音频buffers被释放");else l("未采集到录音")}},k[x]&&(C("重复引入"+x,3),k[x].Destroy()),k[x]=O;var I=function(e,t){t.pos||(t.pos=[0],t.tracks={},t.bytes=[]);var a=t.tracks,s=[t.pos[0]],n=function(){t.pos[0]=s[0]},r=t.bytes.length,i=new Uint8Array(r+e.length);if(i.set(t.bytes),i.set(e,r),t.bytes=i,!t._ht){if(D(i,s),Y(i,s),!L(D(i,s),[24,83,128,103]))return;for(D(i,s);s[0]=e.length)){var n=e[s],r=("0000000"+n.toString(2)).substr(-8),i=/^(0*1)(\d*)$/.exec(r);if(i){var o=i[1].length,_=[];if(!(s+o>e.length)){for(var l=0;le.length)return;for(var i=0;i=c.byteLength?(o-=c.byteLength,l.push(c),e.splice(f,1),f--):(e[f]=c.slice(o),_=c,o=0)}if(!this.rm(e,t)){_&&(e[0]=_);for(f=0;f "+s.duration+"ms",2>=1;0!=e--;)n[r++]=i>a[s++]?0:1,n[r++]=i>a[s++]?0:1}function R(e,t,a,s,n,r){var i=(e>>=1)%2;for(e>>=1;0!=e--;){var o,_,l,f,c,h,u,m;o=a[s++]*t,_=a[s++]*t,c=0|o,l=a[s++]*t,h=0|_,f=a[s++]*t,u=0|l,o+=M.adj43[c],m=0|f,_+=M.adj43[h],n[r++]=0|o,l+=M.adj43[u],n[r++]=0|_,f+=M.adj43[m],n[r++]=0|l,n[r++]=0|f}0!=i&&(c=0|(o=a[s++]*t),h=0|(_=a[s++]*t),o+=M.adj43[c],_+=M.adj43[h],n[r++]=0|o,n[r++]=0|_)}var o=[1,2,5,7,7,10,10,13,13,13,13,13,13,13,13];function d(e,t,a,s){var n=function(e,t,a){var s=0,n=0;do{var r=e[t++],i=e[t++];s>=16)&&(o=r,s++),n.bits+=o,s}(e,t,a,o[n-1],s);case 4:case 5:case 6:case 7:case 8:case 9:case 10:case 11:case 12:case 13:case 14:case 15:return function(e,t,a,s,n){var r=0,i=0,o=0,_=F.ht[s].xlen,l=F.ht[s].hlen,f=F.ht[s+1].hlen,c=F.ht[s+2].hlen;do{var h=e[t+0]*_+e[t+1];t+=2,r+=l[h],i+=f[h],o+=c[h]}while(t=n);r++);for(i=r-8;i<24&&!(F.ht[i].linmax>=n);i++);return function(e,t,a,s,n,r){var i,o=65536*F.ht[s].xlen+F.ht[n].xlen,_=0;do{var l=e[t++],f=e[t++];0!=l&&(14>=16)&&(_=i,s=n),r.bits+=_,s}(e,t,a,i,r,s)}}function u(e,t,a,s,n,r,i,o){for(var _=t.big_values,l=2;l>1<<1);for(null!=a&&(a.sfb_count1=0);1t.big_values&&(r=t.big_values),i=t.big_values;else if(t.block_type==Pe.NORM_TYPE){if(r=t.region0_count=e.bv_scf[n-2],i=t.region1_count=e.bv_scf[n-1],i=e.scalefac_band.l[r+i+2],r=e.scalefac_band.l[r+1],ir)return T.LARGE_BITS;if(function(e,t,a,s,n){var r,i,o,_=0,l=0,f=0,c=0,h=t,u=0,m=h,p=0,b=e,v=0;for(o=null!=n&&s.global_gain==n.global_gain,i=s.block_type==Pe.SHORT_TYPE?38:21,r=0;r<=i;r++){var d=-1;if((o||s.block_type==Pe.NORM_TYPE)&&(d=s.global_gain-(s.scalefac[r]+(0!=s.preflag?M.pretab[r]:0)<s.max_nonzero_coeff&&(g=s.max_nonzero_coeff-_+1,xe.fill(t,s.max_nonzero_coeff,576,0),(S=g)<0&&(S=0),r=i+1),0==l&&0==f&&(m=h,p=u,b=e,v=c),null!=n&&0=n.sfb_count1&&0=n.step[r]?(0!=l&&(R(l,a,b,v,m,p),l=0,m=h,p=u,b=e,v=c),f+=S):(0!=f&&(w(f,a,b,v,m,p),f=0,m=h,p=u,b=e,v=c),l+=S),S<=0){0!=f&&(w(f,a,b,v,m,p),f=0),0!=l&&(R(l,a,b,v,m,p),l=0);break}}r<=i&&(u+=s.width[r],c+=s.width[r],_+=s.width[r])}0!=l&&(R(l,a,b,v,m,p),l=0),0!=f&&(w(f,a,b,v,m,p),f=0)}(t,n,M.IPOW20(a.global_gain),a,s),0!=(2&e.substep_shaping))for(var i=0,o=a.global_gain+a.scalefac_scale,_=.634521682242439/M.IPOW20(o),l=0;l=_?n[f]:0}return this.noquant_count_bits(e,a,s)},this.best_huffman_divide=function(e,t){var a=new y,s=t.l3_enc,n=Ae(23),r=Ae(23),i=Ae(23),o=Ae(23);if(t.block_type!=Pe.SHORT_TYPE||1!=e.mode_gr){a.assign(t),t.block_type==Pe.NORM_TYPE&&(!function(e,t,a,s,n,r,i){for(var o=t.big_values,_=0;_<=22;_++)s[_]=T.LARGE_BITS;for(_=0;_<16;_++){var l=e.scalefac_band.l[_+1];if(o<=l)break;var f=0,c=new v(f),h=d(a,0,l,c);f=c.bits;for(var u=0;u<8;u++){var m=e.scalefac_band.l[_+u+2];if(o<=m)break;var p=f,b=d(a,l,m,c=new v(p));p=c.bits,s[_+u]>p&&(s[_+u]=p,r[(n[_+u]=_)+u]=h,i[_+u]=b)}}}(e,t,s,n,r,i,o),u(e,a,t,s,n,r,i,o));var _=a.big_values;if(!(0==_||1<(s[_-2]|s[_-1])||576<(_=t.count1+2))){a.assign(t),a.count1=_;for(var l=0,f=0;_>a.big_values;_-=4){var c=2*(2*(2*s[_-4]+s[_-3])+s[_-2])+s[_-1];l+=F.t32l[c],f+=F.t33l[c]}if(a.big_values=_,a.count1table_select=0,fa.part2_3_length&&t.assign(a)}}}};var h=[1,1,1,1,8,2,2,2,4,4,4,8,8,8,16,16],m=[1,2,4,8,1,2,4,8,2,4,8,2,4,8,4,8],p=[0,0,0,0,3,1,1,1,2,2,2,3,3,3,4,4],b=[0,1,2,3,0,1,2,3,1,2,3,1,2,3,2,3];k.slen1_tab=p,k.slen2_tab=b,this.best_scalefac_store=function(e,t,a,s){var n,r,i,o,_=s.tt[t][a],l=0;for(n=i=0;n<_.sfbmax;n++){var f=_.width[n];for(i+=f,o=-f;o<0&&0==_.l3_enc[o+i];o++);0==o&&(_.scalefac[n]=l=-2)}if(0==_.scalefac_scale&&0==_.preflag){var c=0;for(n=0;n<_.sfbmax;n++)0<_.scalefac[n]&&(c|=_.scalefac[n]);if(0==(1&c)&&0!=c){for(n=0;n<_.sfbmax;n++)0<_.scalefac[n]&&(_.scalefac[n]>>=1);_.scalefac_scale=l=1}}if(0==_.preflag&&_.block_type!=Pe.SHORT_TYPE&&2==e.mode_gr){for(n=11;nf&&(s.part2_length=f,s.scalefac_compress=r)}}(a,s),l=0),n=0;n<_.sfbmax;n++)-2==_.scalefac[n]&&(_.scalefac[n]=0);0!=l&&(2==e.mode_gr?this.scale_bitcount(_):this.scale_bitcount_lsf(e,_))};var _=[0,18,36,54,54,36,54,72,54,72,90,72,90,108,108,126],l=[0,18,36,54,51,35,53,71,52,70,88,69,87,105,104,122],f=[0,10,20,30,33,21,31,41,32,42,52,43,53,63,64,74];this.scale_bitcount=function(e){var t,a,s,n=0,r=0,i=e.scalefac;if(e.block_type==Pe.SHORT_TYPE)s=_,0!=e.mixed_block_flag&&(s=l);else if(s=f,0==e.preflag){for(a=11;as[t]&&(e.part2_length=s[t],e.scalefac_compress=t);return e.part2_length==T.LARGE_BITS};var g=[[15,15,7,7],[15,15,7,0],[7,3,0,0],[15,31,31,0],[7,7,7,0],[3,3,0,0]];this.scale_bitcount_lsf=function(e,t){var a,s,n,r,i,o,_,l,f=Ae(4),c=t.scalefac;for(a=0!=t.preflag?2:0,_=0;_<4;_++)f[_]=0;if(t.block_type==Pe.SHORT_TYPE){s=1;var h=M.nr_of_sfb_block[a][s];for(n=l=0;n<4;n++)for(r=h[n]/3,_=0;_f[n]&&(f[n]=c[3*l+i])}else{s=0;h=M.nr_of_sfb_block[a][s];for(n=l=0;n<4;n++)for(r=h[n],_=0;_f[n]&&(f[n]=c[l])}for(o=!1,n=0;n<4;n++)f[n]>g[a][n]&&(o=!0);if(!o){var u,m,p,b;for(t.sfb_partition_table=M.nr_of_sfb_block[a][s],n=0;n<4;n++)t.slen[n]=S[f[n]];switch(u=t.slen[0],m=t.slen[1],p=t.slen[2],b=t.slen[3],a){case 0:t.scalefac_compress=(5*u+m<<4)+(p<<2)+b;break;case 1:t.scalefac_compress=400+(5*u+m<<2)+p;break;case 2:t.scalefac_compress=500+3*u+m;break;default:$.err.printf("intensity stereo not implemented yet\n")}}if(!o)for(n=t.part2_length=0;n<4;n++)t.part2_length+=t.slen[n]*t.sfb_partition_table[n];return o};var S=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4];this.huffman_init=function(e){for(var t=2;t<=576;t+=2){for(var a,s=0;e.scalefac_band.l[++s]t;)a--;for(a<0&&(a=n[s][0]),e.bv_scf[t-2]=a,a=n[s][1];e.scalefac_band.l[a+e.bv_scf[t-2]+2]>t;)a--;a<0&&(a=n[s][1]),e.bv_scf[t-1]=a}}}function X(){}function M(){this.setModules=function(e,t,a){e,t,a};var o=[0,49345,49537,320,49921,960,640,49729,50689,1728,1920,51009,1280,50625,50305,1088,52225,3264,3456,52545,3840,53185,52865,3648,2560,51905,52097,2880,51457,2496,2176,51265,55297,6336,6528,55617,6912,56257,55937,6720,7680,57025,57217,8e3,56577,7616,7296,56385,5120,54465,54657,5440,55041,6080,5760,54849,53761,4800,4992,54081,4352,53697,53377,4160,61441,12480,12672,61761,13056,62401,62081,12864,13824,63169,63361,14144,62721,13760,13440,62529,15360,64705,64897,15680,65281,16320,16e3,65089,64001,15040,15232,64321,14592,63937,63617,14400,10240,59585,59777,10560,60161,11200,10880,59969,60929,11968,12160,61249,11520,60865,60545,11328,58369,9408,9600,58689,9984,59329,59009,9792,8704,58049,58241,9024,57601,8640,8320,57409,40961,24768,24960,41281,25344,41921,41601,25152,26112,42689,42881,26432,42241,26048,25728,42049,27648,44225,44417,27968,44801,28608,28288,44609,43521,27328,27520,43841,26880,43457,43137,26688,30720,47297,47489,31040,47873,31680,31360,47681,48641,32448,32640,48961,32e3,48577,48257,31808,46081,29888,30080,46401,30464,47041,46721,30272,29184,45761,45953,29504,45313,29120,28800,45121,20480,37057,37249,20800,37633,21440,21120,37441,38401,22208,22400,38721,21760,38337,38017,21568,39937,23744,23936,40257,24320,40897,40577,24128,23040,39617,39809,23360,39169,22976,22656,38977,34817,18624,18816,35137,19200,35777,35457,19008,19968,36545,36737,20288,36097,19904,19584,35905,17408,33985,34177,17728,34561,18368,18048,34369,33281,17088,17280,33601,16640,33217,32897,16448];this.updateMusicCRC=function(e,t,a,s){for(var n=0;n>8^o[255&(i^r)]);var r,i}}function q(){var _=this,s=32773,c=null,h=null,r=null,u=null;this.setModules=function(e,t,a,s){c=e,h=t,r=a,u=s};var m=null,l=0,p=0,b=0;function v(e,t,a){for(;0>a<>a<>3]|=t>>a<<8-(7&s)-n,s+=n}e.header[e.h_ptr].ptr=s}function n(e,t){e<<=8;for(var a=0;a<8;a++)0!=(65536&((t<<=1)^(e<<=1)))&&(t^=s);return t}function d(e,t){var a,s=F.ht[t.count1table_select+32],n=0,r=t.big_values,i=t.big_values;for(a=(t.count1-t.big_values)/4;0t.big_values&&(a=t.big_values);var s=g(e,t.table_select[0],0,a,t);return s+=g(e,t.table_select[1],a,t.big_values,t)}function M(e,t){var a,s,n,r;a=t.big_values;var i=t.region0_count+1;return n=e.scalefac_band.l[i],i+=t.region1_count+1,a>8),t[5]=byte(255&a)},this.flush_bitstream=function(e){var t,a,s=e.internal_flags,n=s.h_ptr-1;if(-1==n&&(n=G.MAX_HEADER_BUF-1),t=s.l3_side,!((a=R(e,new w))<0)){if(o(e,a),s.ResvSize=0,t.main_data_begin=0,s.findReplayGain){var r=c.GetTitleGain(s.rgdata);s.RadioGain=0|Math.floor(10*r+.5)}s.findPeakSample&&(s.noclipGainChange=0|Math.ceil(20*B(s.PeakSample/32767)*10),0 ResvSize"),8*t.main_data_begin!=a.ResvSize&&($.err.printf("bit reservoir error: \nl3_side.main_data_begin: %d \nResvoir size: %d \nresv drain (post) %d \nresv drain (pre) %d \nheader and sideinfo: %d \ndata bits: %d \ntotal bits: %d (remainder: %d) \nbitsperframe: %d \n",8*t.main_data_begin,a.ResvSize,t.resvDrain_post,t.resvDrain_pre,8*a.sideinfo_len,n-t.resvDrain_post-8*a.sideinfo_len,n,n%8,s),$.err.println("This is a fatal error. It has several possible causes:"),$.err.println("90%% LAME compiled with buggy version of gcc using advanced optimizations"),$.err.println(" 9%% Your system is overclocked"),$.err.println(" 1%% bug in LAME encoding library"),a.ResvSize=8*t.main_data_begin),1e9e.PeakSample?e.PeakSample=_[0][o]:-_[0][o]>e.PeakSample&&(e.PeakSample=-_[0][o]);if(1e.PeakSample?e.PeakSample=_[1][o]:-_[1][o]>e.PeakSample&&(e.PeakSample=-_[1][o])}if(e.findReplayGain&&c.AnalyzeSamples(e.rgdata,_[0],0,_[1],0,f,e.channels_out)==X.GAIN_ANALYSIS_ERROR)return-6}}return r},this.init_bit_stream_w=function(e){m=A(U.LAME_MAXMP3BUFFER),e.h_ptr=e.w_ptr=0,e.header[e.h_ptr].write_timing=0,p=-1,l=b=0}}function e(e,t,a,s){this.xlen=e,this.linmax=t,this.table=a,this.hlen=s}Ee.STEREO=new Ee(0),Ee.JOINT_STEREO=new Ee(1),Ee.DUAL_CHANNEL=new Ee(2),Ee.MONO=new Ee(3),Ee.NOT_SET=new Ee(4),X.STEPS_per_dB=100,X.MAX_dB=120,X.GAIN_NOT_ENOUGH_SAMPLES=-24601,X.GAIN_ANALYSIS_ERROR=0,X.GAIN_ANALYSIS_OK=1,X.INIT_GAIN_ANALYSIS_ERROR=0,X.INIT_GAIN_ANALYSIS_OK=1,X.MAX_ORDER=X.YULE_ORDER=10,X.MAX_SAMPLES_PER_WINDOW=(X.MAX_SAMP_FREQ=48e3)*(X.RMS_WINDOW_TIME_NUMERATOR=1)/(X.RMS_WINDOW_TIME_DENOMINATOR=20)+1,M.NUMTOCENTRIES=100,M.MAXFRAMESIZE=2880,q.EQ=function(e,t){return Math.abs(e)>Math.abs(t)?Math.abs(e-t)<=1e-6*Math.abs(e):Math.abs(e-t)<=1e-6*Math.abs(t)},q.NEQ=function(e,t){return!q.EQ(e,t)};var F={};function j(e){this.bits=e}function x(){this.over_noise=0,this.tot_noise=0,this.max_noise=0,this.over_count=0,this.over_SSD=0,this.bits=0}function r(e,t,a,s){this.l=Ae(1+Pe.SBMAX_l),this.s=Ae(1+Pe.SBMAX_s),this.psfb21=Ae(1+Pe.PSFB21),this.psfb12=Ae(1+Pe.PSFB12);var n=this.l,r=this.s;4==arguments.length&&(this.arrL=e,this.arrS=t,this.arr21=a,this.arr12=s,$.arraycopy(this.arrL,0,n,0,Math.min(this.arrL.length,this.l.length)),$.arraycopy(this.arrS,0,r,0,Math.min(this.arrS.length,this.s.length)),$.arraycopy(this.arr21,0,this.psfb21,0,Math.min(this.arr21.length,this.psfb21.length)),$.arraycopy(this.arr12,0,this.psfb12,0,Math.min(this.arr12.length,this.psfb12.length)))}function T(){var l=null,m=null,s=null;this.setModules=function(e,t,a){l=e,m=t,s=a},this.IPOW20=function(e){return u[e]};var y=2.220446049250313e-16,f=T.IXMAX_VAL+2,c=T.Q_MAX,h=T.Q_MAX2,n=100;this.nr_of_sfb_block=[[[6,5,5,5],[9,9,9,9],[6,9,9,9]],[[6,5,7,3],[9,9,12,6],[6,9,12,6]],[[11,10,0,0],[18,18,0,0],[15,18,0,0]],[[7,7,7,0],[12,12,12,0],[6,15,12,0]],[[6,6,6,3],[12,9,9,6],[6,12,9,6]],[[8,8,5,0],[15,12,9,0],[6,18,9,0]]];var w=[0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0];this.pretab=w,this.sfBandIndex=[new r([0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576],[0,4,8,12,18,24,32,42,56,74,100,132,174,192],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]),new r([0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,332,394,464,540,576],[0,4,8,12,18,26,36,48,62,80,104,136,180,192],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]),new r([0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576],[0,4,8,12,18,26,36,48,62,80,104,134,174,192],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]),new r([0,4,8,12,16,20,24,30,36,44,52,62,74,90,110,134,162,196,238,288,342,418,576],[0,4,8,12,16,22,30,40,52,66,84,106,136,192],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]),new r([0,4,8,12,16,20,24,30,36,42,50,60,72,88,106,128,156,190,230,276,330,384,576],[0,4,8,12,16,22,28,38,50,64,80,100,126,192],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]),new r([0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576],[0,4,8,12,16,22,30,42,58,78,104,138,180,192],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]),new r([0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576],[0,4,8,12,18,26,36,48,62,80,104,134,174,192],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]),new r([0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576],[0,4,8,12,18,26,36,48,62,80,104,134,174,192],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]),new r([0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576],[0,8,16,24,36,52,72,96,124,160,162,164,166,192],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0])];var R=Be(c+h+1),u=Be(c),p=Be(f),b=Be(f);function v(e,t){var a=s.ATHformula(t,e);return a-=n,a=Math.pow(10,a/10+e.ATHlower)}function A(e){this.s=e}this.adj43=b,this.iteration_init=function(e){var t,a=e.internal_flags,s=a.l3_side;if(0==a.iteration_init_init){for(a.iteration_init_init=1,s.main_data_begin=0,function(e){for(var t=e.internal_flags.ATH.l,a=e.internal_flags.ATH.psfb21,s=e.internal_flags.ATH.s,n=e.internal_flags.ATH.psfb12,r=e.internal_flags,i=e.out_samplerate,o=0;o>2&63)&&(t-=64),n=Math.pow(10,t/4/10),32<=(t=e.exp_nspsytune>>8&63)&&(t-=64),r=Math.pow(10,t/4/10),32<=(t=e.exp_nspsytune>>14&63)&&(t-=64),i=Math.pow(10,t/4/10),32<=(t=e.exp_nspsytune>>20&63)&&(t-=64),o=i*Math.pow(10,t/4/10),t=0;t3*s/4&&(f[o]=3*s/4),f[o]<0&&(f[o]=0),f[o]+a[o]>G.MAX_BITS_PER_CHANNEL&&(f[o]=Math.max(0,G.MAX_BITS_PER_CHANNEL-a[o])),i+=f[o];if(hG.MAX_BITS_PER_CHANNEL-e[0]&&(r=G.MAX_BITS_PER_CHANNEL-e[0]),r<0&&(r=0),125<=e[1]&&(125>1,A=0;do{A+=k=f[o]*f[o],M+=k>1;S=d/b,M=y;do{var k,x;A+=k=f[o]*f[o],M+=ks[r-3+1]&&(s[r-3+1]+=(s[r-3]-s[r-3+1])*i.decay),s[r-3+1]>s[r-3+2]&&(s[r-3+2]+=(s[r-3+1]-s[r-3+2])*i.decay))}return _},this.calc_noise_core=function(e,t,a,s){var n=0,r=t.s,i=e.l3_enc;if(r>e.count1)for(;0!=a--;){_=e.xr[r],r++,n+=_*_,_=e.xr[r],r++,n+=_*_}else if(r>e.big_values){var o=Be(2);for(o[0]=0,o[1]=s;0!=a--;){_=Math.abs(e.xr[r])-o[i[r]],r++,n+=_*_,_=Math.abs(e.xr[r])-o[i[r]],r++,n+=_*_}}else for(;0!=a--;){var _;_=Math.abs(e.xr[r])-p[i[r]]*s,r++,n+=_*_,_=Math.abs(e.xr[r])-p[i[r]]*s,r++,n+=_*_}return t.s=r,n},this.calc_noise=function(e,t,a,s,n){var r,i,o=0,_=0,l=0,f=0,c=0,h=-20,u=0,m=e.scalefac,p=0;for(r=s.over_SSD=0;r>1,u+e.width[r]>e.max_nonzero_coeff)i=0<(g=e.max_nonzero_coeff-u+1)?g>>1:0;var M=new A(u);d=this.calc_noise_core(e,M,i,S),u=M.s,null!=n&&(n.step[r]=v,n.noise[r]=d),d=a[o++]=d/t[_++],d=ee.FAST_LOG10(Math.max(d,1e-20)),null!=n&&(n.noise_log[r]=d)}if(null!=n&&(n.global_gain=e.global_gain),c+=d,0a.max_noise-.2&&a.tot_noisea.max_noise-.2&&a.tot_noisea.max_noise-.1&&a.tot_noise+a.over_noisea.max_noise-.15&&a.tot_noise+a.over_noise+a.over_noiset.xrpow_max&&(t.xrpow_max=s[f+c]);if(2==i.noise_shaping_amp)return}}}(e,t,a,s,n);var i=o(t);return!i&&(!(i=2==r.mode_gr?w.scale_bitcount(t):w.scale_bitcount_lsf(r,t))||(1e.xrpow_max&&(e.xrpow_max=t[a+i])}e.scalefac[s]=r>>1}e.preflag=0,e.scalefac_scale=1}(t,s),i=!1):t.block_type==Pe.SHORT_TYPE&&0>t.scalefac_scale))n[s]=f,_+=3*l;else{n[s]=0;var c=210+(f<t.xrpow_max&&(t.xrpow_max=a[_+h]);_+=l*(3-r-1)}}var u=M.IPOW20(202);for(_+=t.width[s]*(r+1),h=-t.width[s];h<0;h++)a[_+h]*=u,a[_+h]>t.xrpow_max&&(t.xrpow_max=a[_+h])}}return!1}(r,t,s)||o(t))),i||(i=2==r.mode_gr?w.scale_bitcount(t):w.scale_bitcount_lsf(r,t)),!i))}this.setModules=function(e,t,a,s){v=e,g=t,this.rv=t,M=a,this.qupvt=a,w=s,n.setModules(M,w)},this.ms_convert=function(e,t){for(var a=0;a<576;++a){var s=e.tt[t][0].xr[a],n=e.tt[t][1].xr[a];e.tt[t][0].xr[a]=(s+n)*(.5*ee.SQRT2),e.tt[t][1].xr[a]=(s-n)*(.5*ee.SQRT2)}},this.init_xrpow=function(e,t,a){var s=0,n=0|t.max_nonzero_coeff;if(t.xrpow_max=0,xe.fill(a,n,576,0),1e-20<(s=function(e,t,a,s){for(var n=s=0;n<=a;++n){var r=Math.abs(e.xr[n]);s+=r,t[n]=Math.sqrt(r*Math.sqrt(r)),t[n]>e.xrpow_max&&(e.xrpow_max=t[n])}return s}(t,a,n,s))){var r=0;0!=(2&e.substep_shaping)&&(r=1);for(var i=0;iS&&o.global_gain<=g;)o.global_gain++;if(o.global_gain>g)break;if(0==f.over_count){for(;(o.part2_3_length=w.count_bits(i,s,o,c))>h&&o.global_gain<=g;)o.global_gain++;if(o.global_gain>g)break}if(M.calc_noise(o,a,l,d,c),d.bits=o.part2_3_length,0!=(A(t.block_type!=Pe.SHORT_TYPE?e.quant_comp:e.quant_comp_short,f,d,o,l)?1:0))h=t.part2_3_length,f=d,t.assign(o),b=0,$.arraycopy(s,0,_,0,576);else if(0==i.full_outer_loop){if(++b>v&&0==f.over_count)break;if(3==i.noise_shaping_amp&&m&&30r[f.VBR_max_bitrate]&&(o[p][v]*=r[f.VBR_max_bitrate],o[p][v]/=u),i[p][v]>o[p][v]&&(i[p][v]=o[p][v]);return h},this.bitpressure_strategy=function(e,t,a,s){for(var n=0;nG.MAX_BITS_PER_CHANNEL&&(s[o][_]=G.MAX_BITS_PER_CHANNEL),m+=s[o][_]}if(G.MAX_BITS_PER_GRANULEG.MAX_BITS_PER_CHANNEL&&(s[o][_]=G.MAX_BITS_PER_CHANNEL),l+=s[o][_];if(l>r[0])for(o=0;o=s?(e.ATH.adjust*=.075*s+.925,e.ATH.adjust=s?e.ATH.adjust=s:e.ATH.adjust>1,u=(h=(c=s)<<1)+c,s=h<<1,r=(n=t)+m;M=e[n+0]-e[n+c],S=e[n+0]+e[n+c],B=e[n+h]-e[n+u],R=e[n+h]+e[n+u],e[n+h]=S-R,e[n+0]=S+R,e[n+u]=M-B,e[n+c]=M+B,M=e[r+0]-e[r+c],S=e[r+0]+e[r+c],B=ee.SQRT2*e[r+u],R=ee.SQRT2*e[r+h],e[r+h]=S-R,e[r+0]=S+R,e[r+u]=M-B,e[r+c]=M+B,r+=s,(n+=s)O[u+3-2]?Q/=O[u+3-2]:Q=O[u+3-2]>10*Q?O[u+3-2]/(10*Q):0,N[u+3]=Q}if(e.analysis){var W=N[0];for(u=1;u<12;u++)WC&&(q[u/3]=u%3+1);for(u=1;u<4;u++){(V[u-1]>V[u]?V[u-1]/V[u]:V[u]/V[u-1])<1.7&&(q[u]=0,1==u&&(q[0]=0))}for(0!=q[0]&&0!=S.nsPsy.lastAttacks[c]&&(q[0]=0),3!=S.nsPsy.lastAttacks[c]&&q[0]+q[1]+q[2]+q[3]==0||((D=0)!=q[1]&&0!=q[0]&&(q[1]=0),0!=q[2]&&0!=q[1]&&(q[2]=0),0!=q[3]&&0!=q[2]&&(q[3]=0)),c<2?x[c]=D:0==D&&(x[0]=x[1]=0),_[c]=S.tot_ener[c],he(e,F,j,M,1&c,w,1&c,s,c,t,a),Me(S,F,R,Y,X),we(S,Y,X,T),v=0;v<3;v++){var J,$;for(ve(e,j,A,B,c,v),pe(S,A,B,c,v),b=0;b1.58*e.thm[1].l[t]||e.thm[1].l[t]>1.58*e.thm[0].l[t])){var a=e.mld_l[t]*e.en[3].l[t],s=Math.max(e.thm[2].l[t],Math.min(e.thm[3].l[t],a));a=e.mld_l[t]*e.en[2].l[t];var n=Math.max(e.thm[3].l[t],Math.min(e.thm[2].l[t],a));e.thm[2].l[t]=s,e.thm[3].l[t]=n}for(t=0;t1.58*e.thm[1].s[t][r]||e.thm[1].s[t][r]>1.58*e.thm[0].s[t][r]||(a=e.mld_s[t]*e.en[3].s[t][r],s=Math.max(e.thm[2].s[t][r],Math.min(e.thm[3].s[t][r],a)),a=e.mld_s[t]*e.en[2].s[t][r],n=Math.max(e.thm[3].s[t][r],Math.min(e.thm[2].s[t][r],a)),e.thm[2].s[t][r]=s,e.thm[3].s[t][r]=n)}(S),g=e.msfix,0g&&(s[_]=g),1a[_]&&(s[_]=a[_]),l.masking_lower<1&&(s[_]*=l.masking_lower)}for(;_f&&(s[r]=f),1a[r]&&(s[r]=a[r]),e.masking_lower<1&&(s[r]*=e.masking_lower)}for(;rM[b+3-2]?E/=M[b+3-2]:E=M[b+3-2]>10*E?M[b+3-2]/(10*E):0,S[b+3]=E}for(b=0;b<3;++b){var P=M[3*b+3]+M[3*b+4]+M[3*b+5],I=1;6*M[3*b+5]B&&(_[m][b/3]=b%3+1);for(b=1;b<4;b++){var H=w[b-1],C=w[b];Math.max(H,C)<4e4&&H<1.7*C&&C<1.7*H&&(1==b&&_[m][0]<=_[m][b]&&(_[m][0]=0),_[m][b]=0)}_[m][0]<=c.nsPsy.lastAttacks[m]&&(_[m][0]=0),3!=c.nsPsy.lastAttacks[m]&&_[m][0]+_[m][1]+_[m][2]+_[m][3]==0||((k=0)!=_[m][1]&&0!=_[m][0]&&(_[m][1]=0),0!=_[m][2]&&0!=_[m][1]&&(_[m][2]=0),0!=_[m][3]&&0!=_[m][2]&&(_[m][3]=0)),m<2?l[m]=k:0==k&&(l[0]=l[1]=0),i[m]=c.tot_ener[m]}}(e,t,a,s,n,r,_,w,R,A),function(e,t){var a=e.internal_flags;e.short_blocks!=ye.short_block_coupled||0!=t[0]&&0!=t[1]||(t[0]=t[1]=0);for(var s=0;s=n&&(p=i*(l[t]-n)/(24-n)+r*(24-l[t])/(24-n)),c[t]=Math.pow(10,p/10),0=n&&(p=_*(l[t]-n)/(24-n)+o*(24-l[t])/(24-n)),c[t]=Math.pow(10,p/10),g=Z.MAX_VALUE;for(v=0;va.npart_l-1&&(a.s3ind[M][1]=a.npart_l-1);var w=576*a.mode_gr/h;if(a.ATH.decay=Math.pow(10,-1.2*w),a.ATH.adjust=.01,-(a.ATH.adjustLimit=1)!=e.ATHtype){var R=e.out_samplerate/Pe.BLKSIZE,A=0;for(t=d=0;t=v)for(l=0;le.in_samplerate&&(e.lowpassfreq=e.in_samplerate/2),e.out_samplerate=(t=0|e.lowpassfreq,a=e.in_samplerate,s=44100,48e3<=a?s=48e3:44100<=a?s=44100:32e3<=a?s=32e3:24e3<=a?s=24e3:22050<=a?s=22050:16e3<=a?s=16e3:12e3<=a?s=12e3:11025<=a?s=11025:8e3<=a&&(s=8e3),-1==t?s:(t<=15960&&(s=44100),t<=15250&&(s=32e3),t<=11220&&(s=24e3),t<=9970&&(s=22050),t<=7230&&(s=16e3),t<=5420&&(s=12e3),t<=4510&&(s=11025),t<=3970&&(s=8e3),a=t.lowpass2&&(a=Math.min(a,r)),t.lowpass1t.highpass1?E((t.highpass2-l)/(t.highpass2-t.highpass1+1e-20)):1,_=t.lowpass2>t.lowpass1?E((l-t.lowpass1)/(t.lowpass2-t.lowpass1+1e-20)):1,t.amp_filter[r]=o*_}}(e),n.samplerate_index=P(e.out_samplerate,e),n.samplerate_index<0)return e.internal_flags=null,-1;if(e.VBR==Te.vbr_off){if(e.free_format)n.bitrate_index=0;else if(e.brate=I(e.brate,e.version,e.out_samplerate),n.bitrate_index=L(e.brate,e.version,e.out_samplerate),n.bitrate_index<=0)return e.internal_flags=null,-1}else n.bitrate_index=1;e.analysis&&(e.bWriteVbrTag=!1),null!=n.pinfo&&(e.bWriteVbrTag=!1),R.init_bit_stream_w(n);for(var c,h,u,m=n.samplerate_index+3*e.version+6*(e.out_samplerate<16e3?1:0),p=0;p=f){var M=i-u;if(0==i&&(M=0),(o=O(e,m[0],m[1],n,r,M))<0)return o;for(r+=o,u+=o,h.mf_size-=e.framesize,h.mf_samples_to_encode-=e.framesize,l=0;li&&(s.ResvMax=i),(s.ResvMax<0||e.disable_reservoir)&&(s.ResvMax=0);var o=t.bits*s.mode_gr+Math.min(s.ResvSize,s.ResvMax);return ad&&(d=e.length,S=A(g=0|1.25*d+7200));var a=n.lame_encode_buffer(v,e,t,e.length,S,0,g);return new Int8Array(S.subarray(0,a))},this.flush=function(){var e=n.lame_encode_flush(v,S,0,g);return new Int8Array(S.subarray(0,e))}}}t(),Recorder.lamejs=t}(); --------------------------------------------------------------------------------