Estoy trabajando en un proyecto en el que necesito grabar audio y permitir que el usuario se detenga cuando termine de grabar. Quiero subir este audio grabado al almacenamiento de Firebase. No estoy seguro de cómo hacerlo.
Estoy compartiendo el enlace de stack blitz donde he implementado la funcionalidad de la grabadora de audio.
https://stackblitz.com/edit/angular-record-rtc-demo
He creado una función de descarga como la siguiente
_downloadFile(data: any, type: string, filename: string): any { const blob = new Blob([data], { type: type }); const url = window.URL.createObjectURL(blob); //this.video.srcObject = stream; //const url = data; const anchor = document.createElement('a'); anchor.download = filename; anchor.href = url; document.body.appendChild(anchor); anchor.click(); document.body.removeChild(anchor); }He creado la función para cargar un archivo como el siguiente
selectFile(event): void { this.isUploading = true this.percentage = 0 const file = event.target.files[0]; this.currentFileUpload = new FileUpload(file); const filePath = `voice`; const fileRef = this.storage.ref(filePath); const task = this.storage.upload(`voice`, file); task .snapshotChanges() .pipe( finalize(() => { this.downloadURL = fileRef.getDownloadURL(); this.downloadURL.subscribe(url => { console.log(url) if (url) { this.isUploading = false this.fb = url; } this.addUrlToEditor(url) task.percentageChanges().subscribe(percentage => { this.percentage = Math.round(percentage); this.percentage = percentage }) }); }) ) .subscribe(url => { if (url) { this.selectedFiles = null; } }); }Puedo descargar el audio. Pero también quiero cargar el audio grabado en el almacenamiento de Firebase y usar esa URL como referencia futura para descargar el audio y otras cosas. Cualquier ayuda será apreciada.
Puede usar this.audioName y this.audioBlob :
const storage = getStorage(); // imported from firebase/storage const storageRef:any = ref(storage, this.audioName); uploadBytes(storageRef, this.audioBlob);Esta solución asume que ya configuró Firebase en su Proyecto Angular.