Java Record/混合两个音频流 [英] Java Record / Mix two audio streams

查看:72
本文介绍了Java Record/混合两个音频流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java应用程序,该应用程序记录来自混音器的音频并将其存储在字节数组中,或将其保存到文件中.我需要的是同时从两个混音器中获取音频,并将其保存到音频文件中(我正在尝试使用.wav).问题是我可以得到两个字节数组,但是不知道如何合并它们(通过合并",我并不是说串联).具体来说,这是一个通过USB调制解调器处理对话的应用程序,我需要将其记录下来(流是每个讲话者的声音,已经被录音以单独记录).

i have a java application that records audio from a mixer and store it on a byte array, or save it to a file. What I need is to get audio from two mixers simultaneously, and save it to an audio file (i am trying with .wav). The thing is that I can get the two byte arrays, but don't know how to merge them (by "merge" i don't mean concatenate). To be specific, it is an application that handles conversations over an USB modem and I need to record them (the streams are the voices for each talking person, already maged to record them separately).

关于如何做到这一点的任何线索?

Any clue on how to do it?

这是我的代码:

import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.Path;

public class FileMixer {

    Path path1 = Paths.get("/file1.wav");
    Path path2 = Paths.get("/file2.wav");
    byte[] byte1 = Files.readAllBytes(path1);
    byte[] byte2 = Files.readAllBytes(path2);
    byte[] out = new byte[byte1.length];

    public FileMixer() {

        byte[] byte1 = Files.readAllBytes(path1);
        byte[] byte2 = Files.readAllBytes(path2);

        for (int i=0; i<byte1.Length; i++)
            out[i] = (byte1[i] + byte2[i]) >> 1;

    }
}

预先感谢

推荐答案

要数字混合声波,请将两个文件中的每个对应数据点相加在一起.

To mix sound waves digitally, you add each corresponding data point from the two files together.

for (int i=0; i<source1.length; i++)
    result[i] = (source1[i] + source2[i]) >> 1;

换句话说,您从字节数组1中取出项目0,从字节数组2中取出项目0,将它们加在一起,然后将结果数字放入结果数组的项目0中.重复其余的值.为避免过载,您可能需要将每个结果值除以二.

In other words, you take item 0 from byte array 1, and item 0 from byte array two, add them together, and put the resulting number in item 0 of your result array. Repeat for the remaining values. To prevent overload, you may need to divide each resulting value by two.

这篇关于Java Record/混合两个音频流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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