On the Noise Problem in Auido2face Flow Mode

@2817359766 It seems you just need to scale the raw_audio_data. Can you try this?

import sys
import time
import audio2face_pb2
import audio2face_pb2_grpc
import grpc
import numpy as np
import soundfile
from pydub import AudioSegment


def push_audio_track_stream(url, audio_data, samplerate, instance_name):
    chunk_size = samplerate // 10  # ADJUST
    sleep_between_chunks = 0.04  # ADJUST
    block_until_playback_is_finished = True  # ADJUST

    with grpc.insecure_channel(url) as channel:
        print("Channel created")
        stub = audio2face_pb2_grpc.Audio2FaceStub(channel)

        def make_generator():
            start_marker = audio2face_pb2.PushAudioRequestStart(
                samplerate=samplerate,
                instance_name=instance_name,
                block_until_playback_is_finished=block_until_playback_is_finished,
            )
            # At first, we send a message with start_marker
            yield audio2face_pb2.PushAudioStreamRequest(start_marker=start_marker)
            # Then we send messages with audio_data
            for i in range(len(audio_data) // chunk_size + 1):
                time.sleep(sleep_between_chunks)
                chunk = audio_data[i * chunk_size : i * chunk_size + chunk_size]                
                yield audio2face_pb2.PushAudioStreamRequest(audio_data=chunk.astype(np.float32).tobytes())

        request_generator = make_generator()
        print("Sending audio data...")
        response = stub.PushAudioStream(request_generator)
        if response.success:
            print("SUCCESS")
        else:
            print(f"ERROR: {response.message}")
    print("Channel closed")


def main():
    sleep_time = 2.0  # ADJUST
    url = "localhost:50051"  # ADJUST
    instance_name = "/World/audio2face/PlayerStreaming"
    audio_data = AudioSegment.from_file("audio_file.wav")
    raw_audio_data = np.array(audio_data.get_array_of_samples(), dtype=np.float32) / 32768.0 # 2 ^ 15

    print(f"Sleeping for {sleep_time} seconds")
    time.sleep(sleep_time)
    push_audio_track_stream(url, raw_audio_data, audio_data.frame_rate, instance_name)


if __name__ == "__main__":
    main()

1 Like