|
@@ -17,6 +17,7 @@ VOICES = {
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
def main():
|
|
|
|
|
+ import struct
|
|
|
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
|
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
|
|
|
|
|
|
|
import win32com.client
|
|
import win32com.client
|
|
@@ -36,7 +37,38 @@ def main():
|
|
|
speaker.AudioOutputStream = stream
|
|
speaker.AudioOutputStream = stream
|
|
|
speaker.Speak(text)
|
|
speaker.Speak(text)
|
|
|
stream.Close()
|
|
stream.Close()
|
|
|
- print(f"生成: {path}")
|
|
|
|
|
|
|
+ with open(path, 'rb+') as f:
|
|
|
|
|
+ data = bytearray(f.read())
|
|
|
|
|
+ fmt_chunk = b'fmt '
|
|
|
|
|
+ fmt_pos = data.find(fmt_chunk)
|
|
|
|
|
+ if fmt_pos == -1:
|
|
|
|
|
+ print(f" 跳过音量放大(无 fmt chunk)")
|
|
|
|
|
+ else:
|
|
|
|
|
+ channels = struct.unpack_from('<H', data, fmt_pos + 10)[0]
|
|
|
|
|
+ sample_rate = struct.unpack_from('<I', data, fmt_pos + 12)[0]
|
|
|
|
|
+ bits_per_sample = struct.unpack_from('<H', data, fmt_pos + 22)[0]
|
|
|
|
|
+ data_chunk = b'data'
|
|
|
|
|
+ data_pos = data.find(data_chunk)
|
|
|
|
|
+ if data_pos != -1:
|
|
|
|
|
+ data_size = struct.unpack_from('<I', data, data_pos + 4)[0]
|
|
|
|
|
+ sample_start = data_pos + 8
|
|
|
|
|
+ sample_end = sample_start + data_size
|
|
|
|
|
+ if bits_per_sample == 16:
|
|
|
|
|
+ fmt = '<' + 'h' * (data_size // 2)
|
|
|
|
|
+ samples = list(struct.unpack_from(fmt, bytes(data[sample_start:sample_end])))
|
|
|
|
|
+ gain = 3.0
|
|
|
|
|
+ samples = [max(-32768, min(32767, int(s * gain))) for s in samples]
|
|
|
|
|
+ data[sample_start:sample_end] = struct.pack(fmt, *samples)
|
|
|
|
|
+ elif bits_per_sample == 8:
|
|
|
|
|
+ samples = list(data[sample_start:sample_end])
|
|
|
|
|
+ gain = 3.0
|
|
|
|
|
+ samples = [max(0, min(255, int((s - 128) * gain) + 128)) for s in samples]
|
|
|
|
|
+ data[sample_start:sample_end] = bytes(samples)
|
|
|
|
|
+ with open(path, 'wb') as f:
|
|
|
|
|
+ f.write(data)
|
|
|
|
|
+ print(f"生成: {path} (增益 {gain}x, {sample_rate}Hz, {bits_per_sample}bit, {channels}ch)")
|
|
|
|
|
+ else:
|
|
|
|
|
+ print(f"生成: {path} (无 data chunk)")
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|