python中声学包产生的布朗噪声的调幅

2024-10-01 02:31:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我对python完全陌生,所以我试着去阅读和学习,但是我似乎做不到我想要的,而且我还没有找到解决堆栈溢出或其他源代码的方法。我的目标是创建一个brown noise的波形文件,在给定的频率下进行幅度调制。我想产生棕色噪音并调节它。在

我打算使用python acoustics package,不幸的是我不知道如何使用函数来创建有色噪声。我看了一些例子,但是我没有看到彩色噪声函数使用的例子。在

有人能帮我解决这个问题吗?谢谢。在


这是我的代码:

""" This file proposes to modulate a given wav file"""

import wave
import struct
import time
import math
import random
import acoustics

###########################################
# General variables
outputName = "waveXP.wav"
frequencyModulation = 40
period = 1/frequencyModulation
duration = 1
maxVolume = 23000.0
framerate = 44100


###########################################
# Ask the user about the output file name
temp = ""
temp = input("Name of the output wave file to import (with extension):")
if temp != "":
    outputName = str(temp)

# Ask the user about the modulation frequency wanted
temp = ""
temp = input("Modulation frequency wanted (in hertz):")
if temp != "":
    frequencyModulation = int(temp)

period = 1/frequencyModulation

# Ask the user about the duration wanted
temp = ""
temp = input("Duration wanted (in seconds):")
if temp != "":
    duration = int(temp)

print("------------------------")


###########################################
# Create the output wave file
newWaveFile = wave.open(outputName, "w")

# Define parameters of the wave file
# nchannels = 1 for mono; sampwidth = 2 for 2 bytes per sample; framerate = 44100 for wave file;
# comptype = "NONE" for no compression support; compname = 'not compressed' for no compression support
newWaveFile.setparams([1, 2, framerate, duration, 'NONE', 'not compressed'])

# Generate noise
newWaveFile.writeframes(struct.pack('h'*framerate*duration, *int(maxVolume*0.7*acoustics.generator.brown(framerate*duration))))

# Close wave files
originalWaveFile.close()
newWaveFile.close()

Tags: theimportforwavetempfileaskduration