pyVoIP
pyVoIP copied to clipboard
read_audio to many noise
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
can you help me @tayler6000 , should i convert packet from PCMA to linier first ?
You should always use linear / raw data when interfacing with pyVoIP. pyVoIP will automatically encode and decode the audio for you.
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
Try
FORMAT = pyaudio.paInt8
I don't really know pyAudio that well, but I think that'll work. See #117
writing the raw audio in a file, it is indeed very noisy
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 ?