Did you test it with another audio format?
Maybe an issue with the encoding?
Note: Speech-to-Text supports WAV files with LINEAR16 or MULAW encoded audio.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
what i am doing right now is recording audio from browser and change it to base64 format from blob and send it to server(PHP) where i am downloading the base64 format in wav file.
If i run this wav file, i can hear the content recorded but if i give path of this audio to google cloud speech to text api, the transcribed result is null.
But if give path of some other sample wav file, that file gets transcribed to text perfectly.
So i dont know what to do to make it work for my recorded Audio .wav file.
Below is the script to get real time audio in browser and send it to php after base64 compression from BLOB
const downloadLink = document.getElementById('download');
const stopButton = document.getElementById('stop');
// generate random stirng
function generateUID(length)
{
return window.btoa(Array.from(window.crypto.getRandomValues(new Uint8Array(length * 2))).map((b) => String.fromCharCode(b)).join("")).replace(/[+/]/g, "").substring(0, length);
}
// generate random stirng
const handleSuccess = function(stream) {
const options = {
mimeType: 'audio/webm'
};
const recordedChunks = [];
const mediaRecorder = new MediaRecorder(stream, options);
mediaRecorder.addEventListener('dataavailable', function(e) {
if (e.data.size > 0) recordedChunks.push(e.data);
});
mediaRecorder.addEventListener('stop', function() {
var blob = downloadLink.href = URL.createObjectURL(new Blob(recordedChunks));
downloadLink.download = 'acetest.wav';
var blob3 = new Blob(recordedChunks);
var reader = new FileReader();
reader.onload = function(event) {
var fd = {};
fd["fname"] = generateUID(8)+".wav";
console.log(fd["fname"]);
fd["data"] = event.target.result;
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: 'POST',
url: "{{ route('user.voice') }}",
data: fd,
dataType: 'text'
}).done(function(data) {
console.log(data);
});
};
reader.readAsDataURL(blob3);
});
stopButton.addEventListener('click', function(){
mediaRecorder.stop();
});
mediaRecorder.start();
};
navigator.mediaDevices.getUserMedia({
audio: true,
video: false
})
.then(handleSuccess);
Here this is the code to download that base64 file to .wav file
$data = substr($request['data'], strpos($request['data'], ",") + 1);
// decode it
$decodedData = base64_decode($data);
// print out the raw data,
$filename = $_POST['fname'];
// write the data out to the file
$folder = storage_path().'/app/public/audios/';
$fp = fopen($folder.$filename, 'wb');
fwrite($fp, $decodedData);
fclose($fp);
@Sinnbeck I used a js library called recorder.js. It gave me the recoding in a proper format and now after uploading it to server it is transcribing the content properly.
Please or to participate in this conversation.