fix: 确保音频数据转换为正确的int16格式后再写入文件
Browse files
app.py
CHANGED
|
@@ -450,7 +450,14 @@ async def text_to_speech(
|
|
| 450 |
|
| 451 |
# 保存为 WAV 文件
|
| 452 |
output_path = "output.wav"
|
| 453 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
|
| 455 |
# 返回音频文件
|
| 456 |
return FileResponse(
|
|
|
|
| 450 |
|
| 451 |
# 保存为 WAV 文件
|
| 452 |
output_path = "output.wav"
|
| 453 |
+
audio_data = output["audio"]
|
| 454 |
+
|
| 455 |
+
# 确保音频数据是正确的格式
|
| 456 |
+
if isinstance(audio_data, np.ndarray):
|
| 457 |
+
# 转换为 int16 格式
|
| 458 |
+
audio_data = (audio_data * 32767).astype(np.int16)
|
| 459 |
+
|
| 460 |
+
sf.write(output_path, audio_data, samplerate=output["sampling_rate"])
|
| 461 |
|
| 462 |
# 返回音频文件
|
| 463 |
return FileResponse(
|