Untitled
unknown
plain_text
a year ago
683 B
3
Indexable
import wave import numpy as np # Parameters sample_rate = 44100 # Sample rate (Hz) duration = 5 # Duration of the audio (seconds) frequency = 440 # Frequency of the sine wave (Hz) amplitude = 32767 # Maximum amplitude for 16-bit WAV files # Generate the sine wave t = np.linspace(0, duration, int(sample_rate * duration), endpoint=False) sine_wave = amplitude * np.sin(2 * np.pi * frequency * t) # Open a WAV file with wave.open("maximum_amplitude_sine_wave.wav", "w") as wf: wf.setnchannels(1) # Mono wf.setsampwidth(2) # 16-bit wf.setframerate(sample_rate) wf.writeframes(sine_wave.astype(np.int16).tobytes())
Editor is loading...
Leave a Comment