如何从声音中获取Pi-Phase以在Python中获得破坏性干扰 [英] How to get Pi-Phase from sound to get a destructive interference in Python

查看:104
本文介绍了如何从声音中获取Pi-Phase以在Python中获得破坏性干扰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先:我不知道该话题放在哪里,因为它是编程和声音问题.如果在错误的位置,请发表评论.

first: I don't know where to put this topic because it's an programming and sound-question. Please comment if it's at the wrong place.

但这是我的问题:如何将声音加载到Python中并为其创建反向声音".因此,当我播放原始文件和"pi移位"文件时,它们会产生破坏性干扰,并且相互抵消,因此您几乎听不到任何声音.有没有要使用的图书馆?

But this is my question: How can I load a sound into Python and create the "reverse-sound" of it. So when I play the original and the "pi-shifted" file, they create an destructive interference and cancel each other out so you hear almost nothing. Are there any Libraries to use?

这里是一个简短的解释性视频.

Here's a small explanation-video.

非常感谢.只是想尝试一下.

Thank you a lot. Just want to experiment a little.

推荐答案

python 中加载音频的最简单方法是使用外部库模块.一旦这样的模块是 pydub .有关详情,请参见此处.

Easiest ways to load audio in python is using external library modules. Once such module is pydub. See here for details.

接下来,您要说的是输入声音的反转相位,这样,当人们将两个具有反相相位的声音相加时,它们就会相互抵消.
相同的主体用于降噪技术.在此处

Next, what you are talking about is reversing phase of input sound such that when one adds two sounds with inverse phase, they cancel each other.
Same principal is used for noise cancelling technology. See details here

下面是一个示例代码,通过合并两个相反相位的声音来演示相位抵消效果.

Below is a sample code that demonstrates phase cancelling effect by merging two sound of opposite phases.

演示代码

from pydub import AudioSegment
from pydub.playback import play

#Load an audio file
myAudioFile = "yourAudioFile.wav"
sound1 = AudioSegment.from_file(myAudioFile, format="wav")

#Invert phase of audio file
sound2 = sound1.invert_phase()

#Merge two audio files
combined = sound1.overlay(sound2)

#Export merged audio file
combined.export("outAudio.wav", format="wav")

#Play audio file :
#should play nothing since two files with inverse phase cancel each other
mergedAudio = AudioSegment.from_wav("outAudio.wav")
play(mergedAudio)

这篇关于如何从声音中获取Pi-Phase以在Python中获得破坏性干扰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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