Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

导出的wav格式音频无法被正确播放 #12

Open
hrf666666 opened this issue Apr 24, 2023 · 3 comments
Open

导出的wav格式音频无法被正确播放 #12

hrf666666 opened this issue Apr 24, 2023 · 3 comments

Comments

@hrf666666
Copy link

我用Ren'Py尝试做一个小demo,采用当前生成的语音文件“11.wav”读取并播放
label start:
play music "audio/11.wav"
play sound "audio/11.wav"
return
均无法正确识别并读取,但是采用potplayer可以正常播放。
在Ren'Py官方文档中写的是支持未压缩的有符号16bit型PCM编码格式的wav文件,这个编码bit可以修改吗,我看导出的是32bit型

@hrf666666
Copy link
Author

hrf666666 commented Apr 24, 2023

将函数moegoe.py下生成语音的语句
write(out_path, hps_ms.data.sampling_rate, audio)
按照wavefile.py下的例子,将其修改成16bit的PCM音频文件
32-bit PCM -2147483648 +2147483647 int32
16-bit PCM -32768 +32767 int16
write("example.wav", samplerate, data.astype(np.int16))
格式修改为:
write(out_path, hps_ms.data.sampling_rate, audio.astype(np.int16))
导出的音频文件在potplaer中播放,直接没有声音了

@hrf666666
Copy link
Author

更新:已解决
将实现方法用基于scipy的方法改成基于soundfile的方法
import soundfile as sf
sf.write(out_path, audio, hps_ms.data.sampling_rate)

@hrf666666
Copy link
Author

hrf666666 commented Apr 24, 2023

PS:尝试使用基于pydub的方法,会出现毛刺噪声的情况,音质下降很明显,切勿使用该方法!
# #pydub实现numpy转语音
# sound = AudioSegment(
# audio.tobytes(),
# frame_rate=hps_ms.data.sampling_rate,
# sample_width=audio.dtype.itemsize,
# channels=1
# )
# sound.export(out_path, format="wav")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant