Voip Server | Voip Client

Voip Server:

import pyaudio
import socket
import sys

# Atamalar
chunk = 1024
p = pyaudio.PyAudio()

stream = p.open(format = pyaudio.paInt16,
channels = 1,
rate = 10240,
output = True)

# Socket Tanimlamalari
host = ”
port = 50000
backlog = 5
size = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host,port))
s.listen(backlog)

client, address = s.accept()

# Ana Fonksiyon
while 1:
data = client.recv(size)
if data:
# ses datasi yaziliyor
stream.write(data) # ses datasi stream a yaziliyor
client.send(‘ACK’) # ACK iletiliyor

client.close()
stream.close()
p.terminate()

Voip Client:

import pyaudio
import socket
import sys
import time

# Atamalar
chunk = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 10240

p = pyaudio.PyAudio()

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

# Socket Tanimlamalari
host = ‘localhost’
port = 50000
size = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))

# Ana Fonksiyon
while 1:
data = stream.read(chunk)
s.send(data)
s.recv(size)

s.close()
stream.close()
p.terminate()

Ses Kaydı – Python

#!/usr/bin/python
import pyaudio
import wave

CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = “seskayit.wav”

p = pyaudio.PyAudio()

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

print(“* kayit ediyor”)

frames = []

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

print(“* kayit tamamlandi”)

stream.stop_stream()
stream.close()
p.terminate()

wf = wave.open(WAVE_OUTPUT_FILENAME, ‘wb’)
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b”.join(frames))
wf.close()