android


NameError: name 'numpydata' is not defined


I'm trying to stream audio from an android application to a python server, I have both codes here.
The client:
public class MainActivity extends AppCompatActivity {
private Button startButton,stopButton;
public byte[] buffer;
public static DatagramSocket socket;
private int port=4100;
AudioRecord recorder;
private int sampleRate = 44100 ; // 44100 for music
private int channelConfig = AudioFormat.CHANNEL_IN_MONO;
private int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
int minBufSize = AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat);
private boolean status = true;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startButton = (Button) findViewById (R.id.start_button);
stopButton = (Button) findViewById (R.id.stop_button);
startButton.setOnClickListener (startListener);
stopButton.setOnClickListener (stopListener);
}
private final OnClickListener stopListener = new OnClickListener() {
#Override
public void onClick(View arg0) {
status = false;
recorder.release();
Log.d("VS","Recorder released");
}
};
private final OnClickListener startListener = new OnClickListener() {
#Override
public void onClick(View arg0) {
status = true;
startStreaming();
}
};
public void startStreaming() {
Thread streamThread = new Thread(new Runnable() {
#Override
public void run() {
try {
DatagramSocket socket = new DatagramSocket();
Log.d("VS", "Socket Created");
byte[] buffer = new byte[minBufSize];
Log.d("VS","Buffer created of size " + minBufSize);
DatagramPacket packet;
Log.d("VS", "Address retrieved");
final InetAddress destination = InetAddress.getByName("192.168.43.71");
Log.d("VS", "Address retrieved");
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,sampleRate,channelConfig,audioFormat,minBufSize*10);
Log.d("VS", "Recorder initialized");
recorder.startRecording();
while(status == true) {
//reading data from MIC into buffer
minBufSize = recorder.read(buffer, 0, buffer.length);
//putting buffer in the packet
packet = new DatagramPacket (buffer,buffer.length,destination,port);
socket.send(packet);
System.out.println("MinBufferSize: " +minBufSize);
}
} catch(UnknownHostException e) {
Log.e("VS", "UnknownHostException",e);
} catch (IOException e) {
e.printStackTrace();
Log.e("VS", ""+ e);
}
}
});
streamThread.start();
}
}
The python server:
import pyaudio
import socket
from threading import Thread
import numpy as np
from matplotlib import pyplot as plt
frames = []
def udpStream(CHUNK):
udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp.bind(("192.165.43.72", 4100))
while True:
# soundData, addr = udp.recvfrom(CHUNK)
soundData, addr = udp.recvfrom(CHUNK * CHANNELS * 2)
frames.append(soundData)
print (numpydata)
plt.plot(numpydata)
plt.show()
udp.close()
def play(stream, CHUNK):
BUFFER = 10
while True:
if len(frames) == BUFFER:
while True:
try:
stream.write(frames.pop(0), CHUNK)
except:
pass
if __name__ == "__main__":
FORMAT = pyaudio.paInt16
CHUNK = 1024
CHANNELS = 2
RATE = 44100
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels = CHANNELS,
rate = RATE,
output = True,
input=True,
frames_per_buffer = CHUNK,
)
Ts = Thread(target = udpStream, args=(CHUNK,))
Tp = Thread(target = play, args=(stream, CHUNK,))
Ts.setDaemon(True)
Tp.setDaemon(True)
Ts.start()
Tp.start()
Ts.join()
Tp.join()
This is not my code, I found it here Noise in Audio Streaming from Android to PC using UDP with Python Server.
I'm not getting any errors on the client, but when I try to run the python server (after installing pyaudio, numpy and matplotlib), I get this error and I don't know why.
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python34\lib\threading.py", line 920, in _bootstrap_inner
self.run()
File "C:\Python34\lib\threading.py", line 868, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Eric\Desktop\Servidor\Servidor.py", line 18, in udpStream
print (numpydata)
NameError: name 'numpydata' is not defined
I don't know how to fix this, could you help me please?
Thank you all!

Related Links

How to mute downlink voice call on android?
Create and use Database in phoneGap is not working
Text to Speech Library Android? [closed]
Actionbar text change while navigating screens
Robolectric: some tests work in Android Studio IDE, but not in Maven
Display Chinese characters from RTF in Android
Is this right way to send JSON data to a web server?
requestLayout() improperly called by android.widget.LinearLayout during layout: running second layout pass
ContentObserver onChange() is not being called.
Missing overflow menu in Android API 10
date and time notification not firing in android
NoClassDefFound Exception on logcat while running the code
Height of view not calculated correctly inside a weighted layout
How to get a particular path from sdcard in android?
Caused by: android.database.sqlite.SQLiteException: no such table: (code 1) Android
How to rotate a view like opening door?

Categories

HOME
google-app-engine
xml
scikit-learn
pagination
toolbox
obfuscation
opendj
telegram-bot
mvc5
vert.x
g++
little-proxy
siddhi
why3
line
jxl
jsonpath
endpoint
android-intent
azure-iot-hub
easyphp
xmonad
delphi-xe5
enterprise-miner
topology
asp.net-core-webapi
selinux
microsoft-ocr
backpack-for-laravel
gulp-watch
php-mysqlidb
roundup
xunit
has-and-belongs-to-many
android-maps
finagle
calculation
fstream
autolisp
android-sugarorm
android-maps-extensions
carriage-return
installscript
alphabetical
google-earth-engine
health-monitoring
typesafe-config
dbnull
contract
phpdbg
getchar
page-replacement
pair-programming
backbone-collections
headless
avx
seq
lsyncd
shinobi
filenet
android-instrumentation
renaming
branch-prediction
greatest-n-per-group
dup
angular-ui-typeahead
toran-proxy
rewrite
intel-c++
fuelcms
phonertc
canalyzer
pyobjc
dnssec
j-security-check
fits
cosine-similarity
iiop
deform
appserver
entry-point
universal-image-loader
ignite-ui
ss7
personalization
twitter-bootstrap-rails
koala
bin
mysql-error-1044
hidapi
beaker-testing
actiondispatch
qi4j
nokia-s40
fragmenttransaction
adobe-media-server
subproject
thttpd
mapping-by-code
window-decoration
matlab-load
multiplatform
w3c-geolocation
cuteeditor
django-paypal
cac
office-2007
eclipse-marketplace
message-passing
zend-rest
qtabbar
dsl-tools
escrow
fdf
firefox-3
unmanagedresources
commercial-application

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App