LiveTalking
LiveTalking copied to clipboard
实时语音推送
我想增加一个功能,直接使用本地音频进行驱动,如何实现
我直接写一个接口传入本地音频路径,进行驱动,下面是主要代码
播放出来的声音和原来的声音 不一致,高声色部分有撕铁皮的声音
从本地文件加载音频数据
audio_data, sample_rate = sf.read(voice_path)
audio_data = audio_data.astype(np.float32)
target_sample_rate = self_sample_rate
if sample_rate != target_sample_rate:
# 计算目标采样点数
# um_target_samples = int(len(audio_data) / sample_rate * target_sample_rate)
# 重采样
# audio_data = resample(audio_data, num_target_samples)
audio_data = resampy.resample(
x=audio_data,
sr_orig=sample_rate,
sr_new=target_sample_rate,
filter='kaiser_best' # 使用高质量的滤波器
)
# 处理音频数据并发送给父类的put_audio_frame方法
streamlen = audio_data.shape[0]
idx = 0
while streamlen >= self_chunk:
nerfreals[sessionid].asr.put_audio_frame(audio_data[idx:idx + self_chunk])
streamlen -= self_chunk
idx += self_chunk
any updates on this? besides, i would love to know the definition of variable self_chunk, cheers~
我直接写一个接口传入本地音频路径,进行驱动,下面是主要代码
播放出来的声音和原来的声音 不一致,高声色部分有撕铁皮的声音
从本地文件加载音频数据
audio_data, sample_rate = sf.read(voice_path) audio_data = audio_data.astype(np.float32) target_sample_rate = self_sample_rate if sample_rate != target_sample_rate: # 计算目标采样点数 # um_target_samples = int(len(audio_data) / sample_rate * target_sample_rate) # 重采样 # audio_data = resample(audio_data, num_target_samples) audio_data = resampy.resample( x=audio_data, sr_orig=sample_rate, sr_new=target_sample_rate, filter='kaiser_best' # 使用高质量的滤波器 ) # 处理音频数据并发送给父类的put_audio_frame方法 streamlen = audio_data.shape[0] idx = 0 while streamlen >= self_chunk: nerfreals[sessionid].asr.put_audio_frame(audio_data[idx:idx + self_chunk]) streamlen -= self_chunk idx += self_chunk
需要是单声道的音频 有api接口 human_audio
@VSycx 是那个重采样的问题,修改一致就可以了