transcription / create_wav.py
AI Assistant
Initial deploy to Hugging Face Spaces
b40215d
raw
history blame contribute delete
677 Bytes
import wave
import struct
import math
sample_rate = 16000
duration = 4.0
frequency = 440.0
with wave.open("test.wav", "w") as wav_file:
wav_file.setnchannels(1)
wav_file.setsampwidth(2)
wav_file.setframerate(sample_rate)
frames = []
for i in range(int(sample_rate * duration)):
t = i / sample_rate
# Make some silence in the middle to simulating turns maybe?
if 1.5 < t < 2.5:
value = 0
else:
value = int(32767.0 * 0.5 * math.sin(2.0 * math.pi * frequency * t))
frames.append(struct.pack('<h', value))
wav_file.writeframes(b''.join(frames))
print("Created test.wav")