[英]How to write Azure Cognitive Services Speech audio output to an Azure Blob?
[英]Azure: Get TTS File with Curl -Cognitive Speech
如何使用音頻文件返回正確的 TTS 響應? 令牌有效,但 TTS 請求無效!
{“代碼”:“404”,“消息”:“找不到資源”}
對於使用此 URL 的令牌 iam: https://westeurope.api.cognitive.microsoft.com/sts/v1.0/issuetoken
我在 Azure 這個網站上找到了這個代碼示例,但它不工作:-/ ( https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/rest-text-to-speech#示例請求 1 )
$token=getToken();
$cont="<speak version='1.0' xml:lang='en-US'><voice xml:lang='en-US' xml:gender='Male'
name='en-US-ChristopherNeural'>
Microsoft Speech Service Text-to-Speech API
</voice></speak>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://westeurope.api.cognitive.microsoft.com/cognitiveservices/v1');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($cont));
$headers = array();
#$headers[] = 'Ocp-Apim-Subscription-Key: xxxxxxxxxxxx';
$headers[] = 'X-Microsoft-OutputFormat: raw-24khz-16bit-mono-pcm';
$headers[] = 'Content-Type: application/ssml+xml';
#$headers[] = 'Host: westus.tts.speech.microsoft.com';
$headers[] = 'Content-Length: '.strlen($cont);
$headers[] = 'Authorization: Bearer '.$token;//Token okay
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
print_r($result); //{"code":"404","message": "Resource not found"}
好的,現在可以了,
我把選項curl_setopt($ch, CURLOPT_HEADER, 1);
獲取有關響應的更多信息,它向我顯示了此錯誤
必需 header 缺少用戶代理。
所以我又給它添加了一個 headerParameter,現在它可以工作了:
$headers[] = 'User-Agent: myApp/1.0.0';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.