LiveTalking icon indicating copy to clipboard operation
LiveTalking copied to clipboard

实时语音推送

Open chenkai89 opened this issue 1 year ago • 1 comments

我想增加一个功能,直接使用本地音频进行驱动,如何实现

chenkai89 avatar Oct 08 '24 06:10 chenkai89

我直接写一个接口传入本地音频路径,进行驱动,下面是主要代码

播放出来的声音和原来的声音 不一致,高声色部分有撕铁皮的声音

从本地文件加载音频数据

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

chenkai89 avatar Oct 10 '24 07:10 chenkai89

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

VSycx avatar Oct 22 '24 08:10 VSycx

需要是单声道的音频 有api接口 human_audio

lipku avatar Nov 15 '24 11:11 lipku

@VSycx 是那个重采样的问题,修改一致就可以了

chenkai89 avatar Dec 05 '24 07:12 chenkai89

@VSycx 是那个重采样的问题,修改一致就可以了

想问一下 这个修改一致是指什么

jleelcb avatar Jul 28 '25 03:07 jleelcb