yuyun2000 / SpeechDenoiser

SpeechDenoiser: Real-Time Speech Denoising with ONNX Welcome to SpeechDenoiser, a simple and effective solution for real-time speech denoising using an ONNX model. This repository contains everything you need to get started with enhancing audio quality by reducing noise, making it perfect for improving voice recordings and live communication.
42 stars 7 forks source link

Process/Provide real time input and output #5

Open hardikdgsa opened 2 months ago

hardikdgsa commented 2 months ago

Thanks for creating a sample code using DeepFilterNet. I want to process this for real-time implementation. Can you please provide the reference or code sample on how to get the live input from the mic process and provide it as the output to the speaker?

yuyun2000 commented 2 months ago

If you just want to use the microphone and speaker on a PC, this is easy to implement and I can write a demo in a short while. If you want to use multiple platforms such as Android, iOS, Linux, etc., I am afraid I don’t have time to do it.

hardikdgsa commented 2 months ago

I want to use it on the PC only. If you can provide the code to take the input, process it, and provide it to the output it will be helpful. Also, do you have any references for using it Virtual microphones, I don't want direct code,however the reference points will be helpful

yuyun2000 commented 2 months ago

chatgpt can help you ,have a try

import pyaudio
import wave

# 录音参数
FORMAT = pyaudio.paInt16  # 16位深度
CHANNELS = 1  # 单声道
RATE = 44100  # 采样率
CHUNK = 1024  # 块大小
RECORD_SECONDS = 5  # 录音时长
OUTPUT_FILENAME = "output.wav"  # 输出文件名

# 初始化pyaudio
audio = pyaudio.PyAudio()

# 打开流
stream = audio.open(format=FORMAT,
                    channels=CHANNELS,
                    rate=RATE,
                    input=True,
                    frames_per_buffer=CHUNK)

print("录音中...")

frames = []

# 开始录音
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
    data = stream.read(CHUNK)
    frames.append(data)

print("录音结束.")

# 停止录音
stream.stop_stream()
stream.close()
audio.terminate()

# 保存录音
with wave.open(OUTPUT_FILENAME, 'wb') as wf:
    wf.setnchannels(CHANNELS)
    wf.setsampwidth(audio.get_sample_size(FORMAT))
    wf.setframerate(RATE)
    wf.writeframes(b''.join(frames))

print(f"文件已保存为 {OUTPUT_FILENAME}")
yuyun2000 commented 2 months ago

I will write a simple code in the next few days to reduce noise in real time directly on the PC

hardikdgsa commented 2 months ago

Thanks a lot for the quick reply. Yes, I am using ChatGPT only in the mean time, however, it is not giving the proper complete answer till now.