I'm using Record RTC using angular and laravel
Angular Code:
sanitize(url: string) {
return this.domSanitizer.bypassSecurityTrustUrl(url);
}
startTimer() {
this.interval = setInterval(() => {
if (this.timeLeft > 0) {
this.timeLeft--;
if (this.timeLeft == 0) {
this.pauseTimer();
this.stopRecording();
}
} else {
this.timeLeft = 30;
}
}, 1000);
}
pauseTimer() {
clearInterval(this.interval);
}
/**
* Start recording.
*/
initiateRecording() {
this.startTimer();
this.recording = true;
let mediaConstraints = {
video: false,
audio: true,
};
navigator.mediaDevices
.getUserMedia(mediaConstraints)
.then(this.successCallback.bind(this), this.errorCallback.bind(this));
}
/**
* Will be called automatically.
*/
successCallback(stream) {
var options = {
mimeType: "audio/wav",
numberOfAudioChannels: 1,
sampleRate: 16000,
};
//Start Actuall Recording
var StereoAudioRecorder = RecordRTC.StereoAudioRecorder;
this.record = new StereoAudioRecorder(stream, options);
this.record.record();
}
/**
* Stop recording.
*/
stopRecording() {
this.recording = false;
this.record.stop(this.processRecording.bind(this));
}
/**
* processRecording Do what ever you want with blob
* @param {any} blob Blog
*/
processRecording(blob) {
this.url = URL.createObjectURL(blob);
var fd = new FormData();
fd.append("audio_data", blob);
fd.append("audio_url", this.url);
return this.http.post(this.baseUrl + "api/auth/post-audio", fd).subscribe(
result => {},
error => {},
);
}
/**
* Process Error.
*/
errorCallback(error) {
this.error = "Can not play audio in your browser";
}
I have to save recorded file in wav format using laravel on server for that i'm using this code:
public function uploadAudio(Request $request)
{
$blobInput = $request->file('audio_data');
Storage::put('audio/test.wav', file_get_contents($blobInput));
return response()->json([
'message' => 'Saved',
], 200);
}
No file is being created in storage folder
Any suggestion to solve this issue, Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire