在客户端将多个音频文件合并为一个音频文件 [英] Joining multiple audio files into a single audio file in client side

查看:75
本文介绍了在客户端将多个音频文件合并为一个音频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用离子框架构建运动应用程序,该应用程序需要按顺序播放多个音频文件,每个音频文件之间有特定间隔.我们得到了这个工作.现在,我们需要将音频文件合并为一个文件.

We are building a exercise app using ionic framework, which need to play multiple audio files in sequence with specific interval between each audio file. We got this working. Now we need to join the audio files into a single file.

示例:File_1(长度为4分钟),File_2(长度为3分钟).我们需要一个新的组合的单个音频文件,该文件的长度应为10分钟(File_1 + 3分钟静默+ File_2)

Example: File_1 (4 mins in length), File_2 (3 mins in length). We need a new combined single audio file which should be of 10 mins length (File_1 + 3 mins silence + File_2)

是否可以使用angular或cordova在客户端移动应用程序中获得此功能?

Is there way to get this in a client side mobile application using angular or cordova?

推荐答案

客户端javascript无法做到这一点,但是可以在服务器端实现.


技术上的基本步骤:

Client-side javascript cannot do that, but it's possible on server-side.


Basic technically steps:

  • 将这些文件发送到服务器
  • 服务器做您想做的一切,并将结果发送回去

如果您使用的是node.js,这很容易

If you are using node.js it's pretty easy

  • send files to server using multer
  • modify files server-side using node-stream and send back


文章描述了node.js上的基本mp3文件串联


This article describes basic mp3 file concatenation on node.js

请注意,这是一种非常骇人听闻的方法,您可能会遇到许多限制(应用程序速度,电池消耗,本地存储限制等),并且您将仍然没有单一文件,而是单一格式.

Note, this is very hackish way, you might hit many restrictions (application speed, battery consumption, local storage limit, etc) and you still will not have single file, but single format.

  • Convert files to base64 using btoa, example

并使用自定义格式,例如

And use custom format like

var CustomFile = function(array_of_base64_files){
    var prepared_files = [];
    for (var i = 0; i < array_of_base64_files.length; i++) {
        var file = array_of_base64_files[i];
        prepared_files.push({
            created: Date.now(),
            order: i,
            base64: file
        });
    };
    this.export = function(){
        return prepared_files;
    }
};

  • 使用 PouchDB 将其保存到浏览器中,它有一些限制,您可以在文档中阅读
  • 要播放时,请从pouchdb中获取 CustomFile
  • 将这些base64解码为文件并使用 window.URL.createObjectURL(formBlob); ,以便HTML5 Audio可以播放
    • Save it to browser by using PouchDB, it has some limits which you can read in docs
    • When you want to play it, get back CustomFile from pouchdb
    • decode those base64 to file and use window.URL.createObjectURL(formBlob); so that HTML5 Audio can play it
    • 这篇关于在客户端将多个音频文件合并为一个音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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