I am using the Speech to text REST
According to the docs, ogg and wav files are supported. However, after uploading required format: wav 16KHZ pcm, I've received the error: {"Message":"Unsupported audio format"}.
I'm using Javascript for the development.
can you share the audio file with us?
I'm using the resource from this link: http://www.lapis-semi.com/en/semicon/speech/sample.html
the PCM 16 bit 16KHZ
Or maybe you can provide me some sample files to test
This site only offers .mp3 files for download, which are not supported. Either convert them to a supported format, for example using Audacity, or use our sample file to test.
The sample file offered also fail.
Can you provide more details about how you are making the request to the REST interface? I got a proper result with the example file using this request (set your key and region accordingly):
curl \
--header "Ocp-Apim-Subscription-Key: ${SPEECHSDK_SPEECH_KEY}" \
--header "Content-type: audio/wav; codecs=audio/pcm; samplerate=16000" \
-X POST \
--data-binary @whatstheweatherlike.wav \
"https://${SPEECHSDK_SPEECH_REGION}.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=en-US" -v
Please also refer to these docs on the REST interface.
Please don't post subscription keys. I would suggest to edit the message to remove the key and regenerate your key from the speech resource in the Azure portal.
handleUpload = () => {
let fd = new FormData();
let upLoadFile = this.state.audioFile[0];
fd.append("audio", upLoadFile);
fetch(
"https://westeurope.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=en-US",
{
method: "POST",
headers: {
"content-type": "audio/ogg; codecs=audio/opus; samplerate=16000",
"Ocp-Apim-Subscription-Key": "my_key",
"Transfer-Encoding": "chunked"
},
body: fd
}
).then(res => console.log(res));
};
This looks ok if you are uploading an ogg file. For a wav file, use "Content-type": "audio/wav; codecs=audio/pcm; samplerate=16000" instead.
Try in that way...still not working with the wav file :(
The SDK solutions seem to work but the api one dopesn't
Try uploading the audio as binary data. This seems to work, but the javascript code is probably not the best:
const fetch = require("node-fetch");
const { createReadStream } = require('fs');
handleUpload = async () => {
let upLoadFile = "whatstheweatherlike.wav";
const stream = createReadStream(upLoadFile);
const response = await fetch(
"https://the_region.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=en-US",
{
method: "POST",
headers: {
"Content-type": "audio/wav; codecs=audio/pcm; samplerate=16000",
"Ocp-Apim-Subscription-Key": "the_key",
"Transfer-Encoding": "chunked"
},
body: stream
}
);
console.log(response);
console.log(response.ok);
const json = await response.json();
console.log(json);
};
handleUpload();
I'm having the same issue, the REST api just gives me { Message: 'Unsupported audio format' }
I'm running the audio file through FFMPEG with settings:
-acodec pcm_s16le -f s16le -ar 16000 -ac 1
Making the request like this:
axios.request(
{
url: AZURE_URL,
method: 'POST',
headers: {
'Ocp-Apim-Subscription-Key': AZURE_API_KEY,
'Content-Type': 'audio/wav; codecs=audio/pcm; samplerate=16000',
Host: 'eastasia.stt.speech.microsoft.com',
'Transfer-Encoding': 'chunked',
},
data: audio,
},
);
Any ideas?
At the end, we solve it. This api wants binary data so make sure you are sending binary data in the body
In my example above audio is a ReadStream, so it should send as binary
what do u put for the url. My case:
fetch(
"https://westeurope.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=en-US",
{
method: "POST",
headers: {
"content-type": "audio/wav; codecs=audio/pcm; samplerate=16000",
"Ocp-Apim-Subscription-Key": "api key",
"Transfer-Encoding": "chunked"
},
body: input.files[0]
}
) .then(res => res.json())
.then(r => {
r = r.DisplayText;
console.log(r);
});
@ionTea: The ffmpeg settings you quote seem to produce a wav file without a RIFF header, which the service can't process. Please try these flags: ffmpeg input.mp3 -acodec pcm_s16le -ar 16000 -ac 1 output.wav, and make sure the output file has the .wav file extension.
Changing the encoding seems to have worked, it's interesting that the old bing API could handle my original ffmpeg settings, but the new cognitive services one couldn't.
Anyways, it seems to be working fine now, thanks!
Alterar a codifica莽茫o parece ter funcionado, 茅 interessante que a antiga API do bing possa lidar com minhas configura莽玫es originais do ffmpeg, mas os novos servi莽os cognitivos n茫o podiam.
De qualquer forma, parece estar funcionando bem agora, obrigado!
Could you tell me how you did to change the encoding? I have the same mistake and can't fix
chlandsi posted the call to ffmpeg that did the trick for him.
There are also many free visual tools that could help you. I had good results with a tool called 'audacity', but again, there are many tools available and it might depend on your usage and requirements
chlandsi postou a liga莽茫o e
ffmpegfez o truque para ele.
Existem tamb茅m muitas ferramentas visuais gratuitas que podem ajud谩-lo. Tive bons resultados com uma ferramenta chamada 'audacity', mas, novamente, existem muitas ferramentas dispon铆veis e isso pode depender do seu uso e requisitos
Thanks!
My application records audio in .wav format, if I convert this file to base 64 and pass it to the API can I get a positive response from it?
@Glauber26 The API expects binary data (no base64 encoding necessary) in the correct audio formats. Please look above for a code sample.
@Glauber26 The API expects binary data (no base64 encoding necessary) in the correct audio formats. Please look above for a code sample.
Thank you for your help! I could solve this by sending the data in binary as you mentioned
Most helpful comment
At the end, we solve it. This api wants binary data so make sure you are sending binary data in the body