"""Create wav file."""
import os
import sys
file_name = input("WAV file name: ")
if os.path.exists(file_name):
print("ERROR: File name is busy")
sys.exit(1)
with open(file_name, "wb") as wav_file:
wav_file.write(
bytes(
(
0x52, 0x49, 0x46, 0x46, # RIFF
# 0x24, 0x08, 0x00, 0x00, # Chunk size = 2084
0xf4, 0x08, 0x00, 0x00, # Chunk size = ???
0x57, 0x41, 0x56, 0x45, # WAVE
0x66, 0x6d, 0x74, 0x20, # fmt
0x10, 0x00, 0x00, 0x00, # Subchunk1 size = 16
0x01, 0x00, # Audio Format = 1 (PCM)
0x02, 0x00, # Num Channels = 2
# 0x01, 0x00, # Num Channels = 1
0x22, 0x56, 0x00, 0x00, # Sample Rate = 22050
0x88, 0x58, 0x01, 0x00, # Byte Rate = 88200
0x04, 0x00, # Block Align = 4
0x10, 0x00, # Bits per sample = 16
0x64, 0x61, 0x74, 0x61, # data
# 0x00, 0x08, 0x00, 0x00, # subchunk size = 2048
0x00, 0xf8, 0x00, 0x00, # subchunk size = ???
0x00, 0x00, # sample 1 left
0x00, 0x00, # sample 1 right
0x24, 0x17, # sample 2 left
0x1e, 0xf3, # sample 2 right
0x3c, 0x13, # sample 3 left
0x3c, 0x14, # sample 3 right
0x16, 0xf9,
0x18, 0xf9,
0x34, 0xe7,
0x23, 0xa6,
0x3c, 0xf2,
0x24, 0xf2,
0x11, 0xce,
0x1a, 0x0d,
)
)
)
for _ in range(1000000):
wav_file.write(
bytes(
(
0x16, 0xf9,
0x18, 0xf9,
0x34, 0xe7,
0x23, 0xa6,
0x3c, 0xf2,
0x24, 0xf2,
0x11, 0xce,
0x1a, 0x0d,
)
)
)
Python заготовка для создания wav-файлов без дополнительных модулей
Добавить комментарий