pyVoIP icon indicating copy to clipboard operation
pyVoIP copied to clipboard

read_audio to many noise

Open adityayudhi opened this issue 1 year ago • 7 comments

hi, i use read_audio to received the caller audio and send to laptop speaker using pyAudio.. but with using read_audio it's to many noise i received.. when i trace using wiresharka, packet from caller is fine, noise is minimize..

from pyVoIP.VoIP import VoIPPhone, InvalidStateError, CallState
import pyVoIP
import time
import wave, io
import pyaudio

CHUNK = 160
FORMAT = pyaudio.paUInt8
CHANNELS = 1
RATE = 8000

p = pyaudio.PyAudio()

stream = p.open(format = FORMAT, channels = CHANNELS, rate = RATE,  input = True, output=True)

def cek_callback(call):
    try:
        print('incoming call')
        call.answer()
        frames = []
        while call.state == CallState.ANSWERED:
            audio_from_caller = call.read_audio()
            
            if audio_from_caller != b"\x80" * len(audio_from_caller):
                stream.write(audio_from_caller)

        call.hangup()
        print('BYE 1')
    except InvalidStateError as e:
        print('invalid state error', str(e))
        print('BYE 2')
    except Exception as e:
        call.hangup()
        print('BYE 3', str(e))

that is my code thankyou

adityayudhi avatar Jun 05 '23 17:06 adityayudhi

gambar

adityayudhi avatar Jun 05 '23 17:06 adityayudhi

can you help me @tayler6000 , should i convert packet from PCMA to linier first ?

adityayudhi avatar Jun 07 '23 06:06 adityayudhi

You should always use linear / raw data when interfacing with pyVoIP. pyVoIP will automatically encode and decode the audio for you.

tayler6000 avatar Jun 07 '23 13:06 tayler6000

i use pyaudio to stream out to the speaker, when i use

CHUNK = 160
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 8000

stream_out = p.open(format = FORMAT, channels = CHANNELS, rate = RATE,  input = True, output=True, frames_per_buffer = CHUNK)

stream_out.write(call.read_audio())

it return too much noise , any advice ? thankyo

adityayudhi avatar Jun 07 '23 16:06 adityayudhi

Try

FORMAT = pyaudio.paInt8

I don't really know pyAudio that well, but I think that'll work. See #117

tayler6000 avatar Jun 08 '23 19:06 tayler6000

writing the raw audio in a file, it is indeed very noisy

elgui avatar Oct 01 '23 15:10 elgui

change this :

FORMAT = pyaudio.paUInt8

and :

in RTPClient.parse_pcmu

def parse_pcmu(self, packet: RTPMessage) -> None:
    data = audioop.ulaw2lin(packet.payload, 1)
    data = audioop.bias(data, 1, 128)
    self.pmin.write(packet.timestamp, data)

change the "128" to an appropriate num, I changed it to 200,the sound become much better!

@tayler6000 how can I use ffplay to play the rtp stream here ?

huakey avatar Jul 25 '24 08:07 huakey