Я совершенно новичок в python, поэтому я пытался читать и изучать все, что мог, но, похоже, не могу делать то, что хочу, и я не нашел решения в Stack Overflow или других источниках. Моя цель — создать волновой файл коричневого шума с амплитудной модуляцией на заданной частоте. Я хочу генерировать коричневый шум и модулировать его.
Я намеревался использовать акустический пакет python, но, к сожалению, не понимаю, как им пользоваться функции для создания цветного шума. Я посмотрел примеры, но я не вижу примеров использования функций цветных шумов.
Кто-нибудь может помочь мне решить эту проблему? Спасибо.
Вот мой код:
""" 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()