{$text} XML; $options = array( 'http' => array( 'header' => "Ocp-Apim-Subscription-Key: $subscriptionKey\r\n" . "Content-Type: application/ssml+xml\r\n" . "X-Microsoft-OutputFormat: $outputFormat\r\n" . "User-Agent: MyTTSApp\r\n", // 添加 User-Agent 头 'method' => 'POST', 'content' => $xmlContent, ), ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); if ($result === FALSE) { // 处理错误 //echo "请求失败"; return json(Tools::set_fail('请求失败')); } else { $date = date("YmdHis"); $root_path = Tools::get_root_path(); $request_path = '/audio/azure_tts'; $save_path = 'public'.$request_path; $filepath = $root_path . $save_path; if (!file_exists($filepath)) { mkdir($filepath, 0777, true); // 确保目录存在 } $filename = "/output_$date.mp3"; file_put_contents($filepath . $filename, $result); //echo "音频文件已生成: $filename"; $domain = request()->domain(); return json(Tools::set_ok('请求成功',$domain.$request_path.$filename)); } } function test(){ } }