Upload edit\Qwen3-TTS-test\simplify-wav.py with huggingface_hub
Browse files
edit//Qwen3-TTS-test//simplify-wav.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import struct
|
| 2 |
+
import math
|
| 3 |
+
import wave
|
| 4 |
+
|
| 5 |
+
def create_silence(filename, duration=2.0):
|
| 6 |
+
num_samples = int(duration * 22050)
|
| 7 |
+
with wave.open(filename, 'wb') as wav:
|
| 8 |
+
wav.setnchannels(1)
|
| 9 |
+
wav.setsampwidth(2)
|
| 10 |
+
wav.setframerate(22050)
|
| 11 |
+
# Silence
|
| 12 |
+
for _ in range(num_samples):
|
| 13 |
+
wav.writeframes(struct.pack('<h', 0))
|
| 14 |
+
print(f'Created {filename}')
|
| 15 |
+
|
| 16 |
+
def create_tone(filename, freq, duration=1.0, vol=0.3):
|
| 17 |
+
num_samples = int(duration * 22050)
|
| 18 |
+
samples = [int(math.sin(2 * math.pi * freq * i / 22050) * 32767 * vol) for i in range(num_samples)]
|
| 19 |
+
with wave.open(filename, 'wb') as wav:
|
| 20 |
+
wav.setnchannels(1)
|
| 21 |
+
wav.setsampwidth(2)
|
| 22 |
+
wav.setframerate(22050)
|
| 23 |
+
wav.writeframes(struct.pack(f'<{len(samples)}h', *samples))
|
| 24 |
+
print(f'Created {filename}')
|
| 25 |
+
|
| 26 |
+
# Create simple files
|
| 27 |
+
create_silence('out/audio/scene01.wav', 0.5)
|
| 28 |
+
create_silence('out/audio/scene02.wav', 0.5)
|
| 29 |
+
create_silence('out/audio/scene03.wav', 0.5)
|
| 30 |
+
create_silence('out/audio/scene04.wav', 0.5)
|
| 31 |
+
create_silence('out/audio/scene05.wav', 0.5)
|
| 32 |
+
create_silence('out/audio/scene06.wav', 0.5)
|
| 33 |
+
create_silence('out/audio/scene07.wav', 0.5)
|
| 34 |
+
create_silence('out/audio/scene08.wav', 0.5)
|
| 35 |
+
create_silence('out/audio/scene09.wav', 0.5)
|
| 36 |
+
print('All files generated!')
|