上传到Google云端存储时转换音频文件 [英] Converting audio file when uploaded to google cloud storage

查看:135
本文介绍了上传到Google云端存储时转换音频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,用户在其中录制音频,然后彼此发送".我之所以写发送",是因为文件实际上存储在服务器上,并在接收者想要收听的时候才提供给接收者.

I have an app, where users record audio and then "send" to each other. I'm writing "send", because actually the file is stored on server, and just provided to the recipient, when they want to listen.

我的问题是,我需要将录制文件(当前为.caf)重新格式化为.mp3,这样它们的尺寸都会变小,以便可以使用我正在使用的音频播放器进行播放.

My issue is, that I need to reformat the recording (currently .caf) to .mp3, so they will be both smaller and so I can play them with the audioplayer I'm using.

那么我的问题是: 是否可以在用户上传时使用云功能触发器,该触发器将使用.caf文件,将其转换并在其中放置.mp3文件?在文档中找不到说明新文件具有相同或不同网址的地方.

My question then is: Is it possible to have a cloud function trigger on user upload, that would take the .caf file, convert it and in its place put a .mp3 file? Can't find anywhere in the docs where it says whether the new file would have same or different url.

推荐答案

是的,如果它存在一个Node.js库,它可以完成从.caf到.mp3的转换,则可以实现.您最好应该使用通过promise处理异步任务的库.

Yes, this would be possible if it exists a Node.js library that does the conversion from .caf to .mp3. You should preferably work with a library that handle asynchronous tasks through promises.

由于要编写其他文件(扩展名不同),因此下载URL将有所不同.但是管理这种情况应该不是问题:您可以为mp3文件生成一个新的下载URL,然后将其保存在数据库中(或动态生成该URL,如

Since you are going to write a different file (different extension) the download URL will be different. But it should not be a problem to manage this situation: you can generate a new download URL for the mp3 file and, for example, save it in the database (or generate this URL on the fly, as shown here in the doc).

您会在官方云函数示例的集合中找到一些操纵文件的云函数(特别是使用tmp目录).例如,有 generate-thumbnail 中等图像.

You will find in the collection of official Cloud Functions samples some Cloud Functions that manipulate files (and in particular use the tmp directory for that). For example there is the generate-thumbnail and the moderate-images.

但是,您必须考虑到Cloud Function的最大执行时间是9分钟.因此,如果您的某些音频文件需要超过9分钟的转换处理,那就是一个问题.

However, you have to take into account that the maximum execution time for a Cloud Function is 9 minutes. So if some of your audio files need more than 9 minutes of transformation processing it will be a problem.

这篇关于上传到Google云端存储时转换音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆