- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 python 进行编码并使用“wave”库。我已经成功地用这个库保存了新的波形文件,但两个声音文件没有重叠 - 它们在保存时会一个接一个地播放。如果有人可以帮助如何保存两个轨道同时以不同音量播放的文件,那就太好了。谢谢。
最佳答案
您可以使用 pydub 库(我在 std 库中围绕 python wave 模块编写的一个轻型包装器)来非常简单地完成此操作:
from pydub import AudioSegment
sound1 = AudioSegment.from_file("/path/to/my_sound.wav")
sound2 = AudioSegment.from_file("/path/to/another_sound.wav")
combined = sound1.overlay(sound2)
combined.export("/path/to/combined.wav", format='wav')
但是如果你真的想使用wave来做到这一点:
这非常依赖于它们所采用的格式。以下是假设 2 字节宽、小尾数法样本的示例:
import wave
w1 = wave.open("/path/to/wav/1")
w2 = wave.open("/path/to/wav/2")
#get samples formatted as a string.
samples1 = w1.readframes(w1.getnframes())
samples2 = w2.readframes(w2.getnframes())
#takes every 2 bytes and groups them together as 1 sample. ("123456" -> ["12", "34", "56"])
samples1 = [samples1[i:i+2] for i in xrange(0, len(samples1), 2)]
samples2 = [samples2[i:i+2] for i in xrange(0, len(samples2), 2)]
#convert samples from strings to ints
def bin_to_int(bin):
as_int = 0
for char in bin[::-1]: #iterate over each char in reverse (because little-endian)
#get the integer value of char and assign to the lowest byte of as_int, shifting the rest up
as_int <<= 8
as_int += ord(char)
return as_int
samples1 = [bin_to_int(s) for s in samples1] #['\x04\x08'] -> [0x0804]
samples2 = [bin_to_int(s) for s in samples2]
#average the samples:
samples_avg = [(s1+s2)/2 for (s1, s2) in zip(samples1, samples2)]
现在剩下要做的就是将 samples_avg
转换回二进制字符串,并使用 wave.writeframes
将其写入文件。这与我们刚刚所做的相反,所以应该不难理解。对于 int_to_bin 函数,您可能会使用函数 chr(code)
,该函数返回字符代码为 code
的字符(与 ord 相反)
关于python - 如何保存同时播放两个轨道的wav文件?不同体积的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43160498/
我正在尝试让这段代码计算盒子的表面积和体积。它编译但不输出正确的数据。我认为问题可能出在 void Box::零件内,但碰壁了。或者它可能是 Height = Height 但我无法以任何其他方式让它
我需要一个使用 kinect 计算 body 体积(以立方米为单位)的算法。我知道我可以提取云和深度框架(通过使用骨架 NUI 的一些方法隔离 body )但我不知道如何从这个矩阵计算体积值。导出卷
我是 d3 的新手,并试图根据节点之间的连接数使链接的宽度动态化。比方说,我们有: "links": [ { "source": a, "target": b},
我要渲染 3D 数据,它是一个一维数组。此数据在将进行可视化的同一程序中预先计算。数据表示统一的 3D 网格。网格的每个单元格都由一个 vector 组成。 GridSize = dx * dy *
我尝试在 jupyter notebook 中使用 mayavi 渲染体积来测试下面的示例 from mayavi import mlab mlab.init_notebook() x, y, z =
我尝试了几种不同的方法。我需要使用继承来扩展这些类。每次我运行该程序时,它都会输出 0.0 的体积和面积。半径显示正确。输出在底部。 public class Base_HW04Q1 { pu
我参与了一个项目,我需要根据体积的一系列图像渲染 3D 体积。这些图像是通过多种技术创建的,因此它们是所讨论对象的垂直切片。 数据集类似于this question , 但提问者正在寻找 Matlab
已关闭。此问题旨在寻求有关书籍、工具、软件库等的建议。不符合Stack Overflow guidelines准则。它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,
我想知道是否有任何基于 numpy 的工具可以: 给定一个二值输入的 3D numpy 图像,找到它的凸包; 并返回索引列表或此 3D 凸包内的体素(3D 像素)的类似物。 一种可能是使用skimag
我要使用 Matlab 从灰度图像集创建一个 3D 体积。一组包含二维灰度图像的连续量化切片。我仍然认为自己是 Matlab 的菜鸟,但这是我目前的想法: 为 3D 体积创建一个空白空间。 在每张图片
我有一个 3D 体积和一个 2D 图像以及两者之间的近似映射(没有倾斜的仿射变换,已知缩放,旋转和平移近似已知并且需要拟合)。因为这个映射有错误,我想进一步将 2D 图像注册到 3D 体积。我以前没有
更新: 我创建了一个文档齐全的 ipython 笔记本。如果您只想要代码,请查看第一个答案。 问题 我有一个 40x40x40 体积的灰度值。这需要旋转/移动/剪切。 这是一组有用的齐次变换:http
看似简单的问题,没有图像处理/处理经验的人其实没那么容易。 我不只是想将 2D 阵列堆叠在一起,而是通过合并多个由空白分隔的二进制 2D 切片来创建 3D 体积。 例子: 用零定义一个 3D 矩阵:
我非常沮丧,因为几个小时后,我似乎无法在 python 中进行看似简单的 3D 插值。在 Matlab 中,我所要做的就是 Vi = interp3(x,y,z,V,xi,yi,zi) 使用 scip
我是一名优秀的程序员,十分优秀!