question

vikram kaledhonkar avatar image
vikram kaledhonkar asked

Null pointer exception for reference implementation

(I posted the issue into another thread, but that thread was 'answered' and this is slightly different issue, so posting new one). I am following steps in https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/docs/reference-implementation-guide Running sample on Windows laptop with VLC. When I click 'start listening', my client gives null pointer error. After some debug it seems like that is happening because AVS is returning 204 response code where it was not expected. Here is the stack trace, can someone help? ===== java.util.concurrent.ExecutionException: java.lang.NullPointerException at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252) at java.util.concurrent.FutureTask.get(FutureTask.java:111) at javax.swing.SwingWorker.get(SwingWorker.java:602) at com.amazon.alexa.avs.AVSApp$1$1.done(AVSApp.java:83) at javax.swing.SwingWorker$5.run(SwingWorker.java:737) at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(SwingWorker.java:832) at sun.swing.AccumulativeRunnable.run(AccumulativeRunnable.java:112) at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(SwingWorker.java:842) at javax.swing.Timer.fireActionPerformed(Timer.java:312) at javax.swing.Timer$DoPostEvent.run(Timer.java:244) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:701) at java.awt.EventQueue.access$000(EventQueue.java:102) at java.awt.EventQueue$3.run(EventQueue.java:662) at java.awt.EventQueue$3.run(EventQueue.java:660) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:671) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139) at java.awt.EventDispatchThread.run(EventDispatchThread.java:97) Caused by: java.lang.NullPointerException at com.amazon.alexa.avs.AVSClient.finishRequest(AVSClient.java:164) at com.amazon.alexa.avs.AVSController.startRecording(AVSController.java:67) at com.amazon.alexa.avs.AVSApp$1$1.doInBackground(AVSApp.java:76) at com.amazon.alexa.avs.AVSApp$1$1.doInBackground(AVSApp.java:1) at javax.swing.SwingWorker$1.call(SwingWorker.java:296) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at javax.swing.SwingWorker.run(SwingWorker.java:335) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722)
alexa voice service
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

E. McDonald avatar image
E. McDonald answered
I've noticed 204 responses as well (see https://forums.developer.amazon.com/forums/thread.jspa?threadID=8875) and I believe the issue may be related to having input audio that is sampled at a rate too far away from what is specified in the metadata, etc. You should try to verify that your recording is actually 16k mono and see if that helps.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

swasey@amazon avatar image
swasey@amazon answered
As E. Mcdonald has pointed out your problem of getting a 204 is probably due to the invalid audio format. Have you modified the code at all before running it, or do you receive this exception "out of the box"? If you didn't modify the code at all, then this is more concerning, so it might be a problem on the server or specifically with your environment. The headers of the response should be logged to your console when running the sample, so if you could provide the value associated with "x-amzn-RequestId" then we can figure out on the server what might be the issue. The code currently on the developer website handles 204's inappropriately (causing the NPE). We've been aware of the issue and have a fix in flight that will be made available soon. I'll also be filing a bug on the dev team to handle returning an appropriate error message and code when the audio is not correct. Thanks, Zach
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

spotnag avatar image
spotnag answered
Hello, I have just finished the full implementation of the amazon alexa guide on the raspberry pi. Once i fire up the companionServer and then start the client, i activate the token successfully and then click 'start listening'. After the meta data request, i can see in the audio box its picking up input but i get the below response. Im using a headset USB device for input. Im guessing im probably having the same problem as explained above. Could you tell me though, How do i set the sampling to 16k? Do i need to buy a mic that only records in mono 16k? I have no experience with audio controls i'm afraid, especially in linux. 16:58:47.843 [DownchannelRequestThread] INFO com.amazon.alexa.avs.http.MessageParser - Response metadata: { "directive" : { "header" : { "namespace" : "SpeechRecognizer", "name" : "StopCapture", "messageId" : "f1e2ff93-3d5e-4675-bb86-96f2696fea8d" }, "payload" : { } } } 16:58:49.385 [IndependentDirectiveThread] INFO com.amazon.alexa.avs.AVSController - Handling directive: SpeechRecognizer.StopCapture 16:58:58.616 [RequestThread] INFO com.amazon.alexa.avs.http.AVSClient - Response code: 204 16:58:58.639 [RequestThread] INFO com.amazon.alexa.avs.http.AVSClient - Response headers: access-control-allow-origin: * x-amzn-requestid: 0eed6ffffeef7485-0000220e-0001302e-dd14500b489c916a-faf8fb4d-5-
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

swasey@amazon avatar image
swasey@amazon answered
Hey spotnag, it's hard to diagnose without knowing the specific mic and having access to it, but you can test some things with a utility called arecord. For example, try running "arecord --list-devices" to list out the devices that ALSA (a linux audio subsystem) is able to find. Then you can run the following command to test different devices and make sure that your voice is actually being recorded: arecord -D $DEVICE --channels=1 --file-type=wav --rate=16000 -f S16_LE test.wav Then test playing it with: aplay test.wav This thread will also be helpful for testing: http://www.voxforge.org/home/docs/faq/faq/linux-how-to-determine-your-audio-cards-or-usb-mics-maximum-sampling-rate If your microphone is unable to record at the appropriate sample rate it might not be able to be used with AVS.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

spotnag avatar image
spotnag answered
Hello, I have tried the microphone using the command you listed above. Both on 16000 and 48000 its clear sound recorded and i can hear it clearly through aplay after. How do i know which sampling rate the program is using though? do you convert it on your side to 16000 or is that done on my side? thanks.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

swasey@amazon avatar image
swasey@amazon answered
Hey spotnag, sorry for the delay. The code in the reference implementation delegates all sampling to the JVM. We just ask for a microphone, and open it with an AudioFormat set to 16000hz, 16 bit, single channel. You can see this code in the AudioCapture class, in the startCapture method and the audioFormat that gets passed in. I'm currently requesting access internally to determine if your speech is being recorded properly and we can figure out next steps from there.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

swasey@amazon avatar image
swasey@amazon answered
Hey spotnag, so I checked your utterance and there's definitely a problem with recording. Our code selects the default microphone on the system, which is handled by the OS. For some reason Raspbian isn't recognizing your USB headset as the default microphone on the system. The good thing is that there is a wealth of information on how to set a USB microphone to be the default. Because things might be slightly different with your specific USB headset, it'll be difficult for me to provide direct support, but I can provide you with some links I found: http://raspberrypi.stackexchange.com/questions/37177/best-way-to-setup-usb-mic-as-system-default-on-raspbian-jessie http://computers.tutsplus.com/articles/using-a-usb-audio-device-with-a-raspberry-pi--mac-55876 And searching "raspbian set default microphone" has many positive looking links to help you out as well. Now that you've found the correct device via arecord it should be easy to follow one of these guides and get something working. Please report back if even after looking at these links it still doesn't work.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.