Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #105896
| X-Received | by 10.50.142.66 with SMTP id ru2mr6397528igb.8.1459152610647; Mon, 28 Mar 2016 01:10:10 -0700 (PDT) |
|---|---|
| X-Received | by 10.50.43.234 with SMTP id z10mr82789igl.4.1459152610617; Mon, 28 Mar 2016 01:10:10 -0700 (PDT) |
| Path | csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!nt3no5229609igb.0!news-out.google.com!pn7ni17040igb.0!nntp.google.com!nt3no5229599igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Mon, 28 Mar 2016 01:10:10 -0700 (PDT) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=14.139.238.98; posting-account=2z6l7woAAAAgv8YY_SbqiC9D55SzPQj9 |
| NNTP-Posting-Host | 14.139.238.98 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <2aa228df-4ee4-4515-a013-cf2d65502dd0@googlegroups.com> (permalink) |
| Subject | Pyaudio and sockets |
| From | Shiva Upreti <katewinslet626@gmail.com> |
| Injection-Date | Mon, 28 Mar 2016 08:10:10 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Xref | csiph.com comp.lang.python:105896 |
Show key headers only | View raw
I am trying to send audio using sockets to a different PC, but audio is not clear on the other end and I cant understand why. Here is the code: import socket import pyaudio import wave import sys import pickle import time HOST="" PORT=1061 s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) CHUNK = 1024 FORMAT = pyaudio.paInt16 CHANNELS = 2 RATE = 44100 RECORD_SECONDS = 3 def record(sock): def callback_record(in_data, frame_count, time_info, status): #print len(in_data) sock.sendall(in_data) return (in_data, pyaudio.paContinue) p = pyaudio.PyAudio() stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, output=False, stream_callback=callback_record) stream.start_stream() return stream def play(sock): def callback_play(in_data, frame_count, time_info, status): #msg=recv_all(sock) in_data=sock.recv(5000) return (in_data, pyaudio.paContinue) p = pyaudio.PyAudio() stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=False, output=True, stream_callback=callback_play) stream.start_stream() return stream def recv_all(sock): data=sock.recv(5000) return data if sys.argv[1] == 'server': s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((HOST, PORT)) s.listen(10) while(True): print "Listening at:", s.getsockname() sc, addr=s.accept() print "Connection established with:", addr while True: stream_record=record(sc) #stream_play=play(sc) while stream_record.is_active(): #time.sleep(0.0) pass #stream_record.stop_stream() #stream_record.close() #stream_play.stop_stream() #stream_play.close() elif sys.argv[1]=='client': s.connect((HOST, PORT)) while True: stream_play=play(s) #time.sleep(5) #stream_record=record(s) while stream_play.is_active(): #time.sleep(0.0) pass #stream_record.stop_stream() #stream_record.close() #stream_play.stop_stream() #stream_play.close() To run it as server enter this command: python audio_chat2.py server To run it as client enter this command: python audio_chat2.py client I also tried running them on same PC, still voice was not clear.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Pyaudio and sockets Shiva Upreti <katewinslet626@gmail.com> - 2016-03-28 01:10 -0700
csiph-web