Giter VIP home page Giter VIP logo

alexaandroid's Introduction

Alexa Voice Library

=======

A library and sample app to abstract access to the Amazon Alexa service for Android applications.

First and foremost, my goal with this project is to help others who have less of an understanding of Java, Android, or both, to be able to quickly and easily integrate the Amazon Alexa platform into their own applications.

For getting started with the Amazon Alexa platform, take a look over here: https://developer.amazon.com/appsandservices/solutions/alexa/alexa-voice-service/getting-started-with-the-alexa-voice-service

Library updated with functionality for the Alexa v20160207 API version.

Applications

Sample Application

Curious about what the library can do? A quick example of the three main functions (live recorded audio events, text-to-speech intents, prerecorded audio intents), plus sample code can be found in the sample app

Compiling and running the sample application

  • Follow the process for creating a connected device detailed at the Amazon link at the top of the Readme.
  • Add your api_key.txt file (part of the Amazon process) to the app/src/main/assets folder
  • Change PRODUCT_ID to the value for my Alexa application that you configured for "Application Type Id" above.
  • Build and run the sample app using Gradle from the command line or Android Studio!

Production Application

Or see what the library can do when converted into a full package, complete with optional always-on listener: Alexa Listens

Using the Library

Most of the library can be accessed through the AlexaManager and AlexaAudioPlayer classes, both of which are singletons.

Installation

  • Ensure you're pulling from jcenter() for your project (project-level build.gradle):
buildscript {
    repositories {
        jcenter()
    }
    ...
}

allprojects {
    repositories {
        jcenter()
    }
}
  • Add the library to your imports (application-level build.gradle):
compile 'com.willblaschko.android.alexa:AlexaAndroid:2.4.2'
  • Follow the process for creating a connected device detailed in the Amazon link at the top of the Readme.
  • Follow the instructions for adding your key and preparing the Login with Amazon activity from the 'Login with Amazon' Android Project guide
  • Add your api_key.txt file (part of the Login with Amazon process detailed in the link above) to the app/src/main/assets folder.
  • Start integration and testing!

Library Instantiation and Basic Return Parsing

private AlexaManager alexaManager;
private AlexaAudioPlayer audioPlayer;
private List<AvsItem> avsQueue = new ArrayList<>();

private void initAlexaAndroid(){
	//get our AlexaManager instance for convenience
	alexaManager = AlexaManager.getInstance(this, PRODUCT_ID);

	//instantiate our audio player
	audioPlayer = AlexaAudioPlayer.getInstance(this);

	//Callback to be able to remove the current item and check queue once we've finished playing an item
	audioPlayer.addCallback(alexaAudioPlayerCallback);
}

//Our callback that deals with removing played items in our media player and then checking to see if more items exist
private AlexaAudioPlayer.Callback alexaAudioPlayerCallback = new AlexaAudioPlayer.Callback() {
	@Override
	public void playerPrepared(AvsItem pendingItem) {

	}

	@Override
	public void itemComplete(AvsItem completedItem) {
		avsQueue.remove(completedItem);
		checkQueue();
	}

	@Override
	public boolean playerError(int what, int extra) {
		return false;
	}

	@Override
	public void dataError(Exception e) {

	}
};

//async callback for commands sent to Alexa Voice
private AsyncCallback<AvsResponse, Exception> requestCallback = new AsyncCallback<AvsResponse, Exception>() {
	@Override
	public void start() {
		//your on start code
	}

	@Override
	public void success(AvsResponse result) {
		Log.i(TAG, "Voice Success");
		handleResponse(result);
	}

	@Override
	public void failure(Exception error) {
		//your on error code
	}

	@Override
	public void complete() {
		 //your on complete code
	}
};

/**
 * Handle the response sent back from Alexa's parsing of the Intent, these can be any of the AvsItem types (play, speak, stop, clear, listen)
 * @param response a List<AvsItem> returned from the mAlexaManager.sendTextRequest() call in sendVoiceToAlexa()
 */
private void handleResponse(AvsResponse response){
	if(response != null){
		//if we have a clear queue item in the list, we need to clear the current queue before proceeding
		//iterate backwards to avoid changing our array positions and getting all the nasty errors that come
		//from doing that
		for(int i = response.size() - 1; i >= 0; i--){
			if(response.get(i) instanceof AvsReplaceAllItem || response.get(i) instanceof AvsReplaceEnqueuedItem){
				//clear our queue
				avsQueue.clear();
				//remove item
				response.remove(i);
			}
		}
		avsQueue.addAll(response);
	}
	checkQueue();
}


/**
 * Check our current queue of items, and if we have more to parse (once we've reached a play or listen callback) then proceed to the
 * next item in our list.
 *
 * We're handling the AvsReplaceAllItem in handleResponse() because it needs to clear everything currently in the queue, before
 * the new items are added to the list, it should have no function here.
 */
private void checkQueue() {

	//if we're out of things, hang up the phone and move on
	if (avsQueue.size() == 0) {
		return;
	}

	AvsItem current = avsQueue.get(0);

	if (current instanceof AvsPlayRemoteItem) {
		//play a URL
		if (!audioPlayer.isPlaying()) {
			audioPlayer.playItem((AvsPlayRemoteItem) current);
		}
	} else if (current instanceof AvsPlayContentItem) {
		//play a URL
		if (!audioPlayer.isPlaying()) {
			audioPlayer.playItem((AvsPlayContentItem) current);
		}
	} else if (current instanceof AvsSpeakItem) {
		//play a sound file
		if (!audioPlayer.isPlaying()) {
			audioPlayer.playItem((AvsSpeakItem) current);
		}
	} else if (current instanceof AvsStopItem) {
		//stop our play
		audioPlayer.stop();
		avsQueue.remove(current);
	} else if (current instanceof AvsReplaceAllItem) {
		audioPlayer.stop();
		avsQueue.remove(current);
	} else if (current instanceof AvsReplaceEnqueuedItem) {
		avsQueue.remove(current);
	} else if (current instanceof AvsExpectSpeechItem) {
		//listen for user input
		audioPlayer.stop();
		startListening();
	} else if (current instanceof AvsSetVolumeItem) {
		setVolume(((AvsSetVolumeItem) current).getVolume());
		avsQueue.remove(current);
	} else if(current instanceof AvsAdjustVolumeItem){
		adjustVolume(((AvsAdjustVolumeItem) current).getAdjustment());
		avsQueue.remove(current);
	} else if(current instanceof AvsSetMuteItem){
		setMute(((AvsSetMuteItem) current).isMute());
		avsQueue.remove(current);
	}else if(current instanceof AvsMediaPlayCommandItem){
		//fake a hardware "play" press
		sendMediaButton(this, KeyEvent.KEYCODE_MEDIA_PLAY);
	}else if(current instanceof AvsMediaPauseCommandItem){
		//fake a hardware "pause" press
		sendMediaButton(this, KeyEvent.KEYCODE_MEDIA_PAUSE);
	}else if(current instanceof AvsMediaNextCommandItem){
		//fake a hardware "next" press
		sendMediaButton(this, KeyEvent.KEYCODE_MEDIA_NEXT);
	}else if(current instanceof AvsMediaPreviousCommandItem){
		//fake a hardware "previous" press
		sendMediaButton(this, KeyEvent.KEYCODE_MEDIA_PREVIOUS);
	}

}

//our call to start listening when we get a AvsExpectSpeechItem
protected abstract void startListening();

//adjust our device volume
private void adjustVolume(long adjust){
	setVolume(adjust, true);
}

//set our device volume
private void setVolume(long volume){
	setVolume(volume, false);
}

//set our device volume, handles both adjust and set volume to avoid repeating code
private void setVolume(final long volume, final boolean adjust){
	AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
	final int max = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
	long vol= am.getStreamVolume(AudioManager.STREAM_MUSIC);
	if(adjust){
		vol += volume * max / 100;
	}else{
		vol = volume * max / 100;
	}
	am.setStreamVolume(AudioManager.STREAM_MUSIC, (int) vol, AudioManager.FLAG_VIBRATE);
	//confirm volume change
	alexaManager.sendVolumeChangedEvent(volume, vol == 0, requestCallback);
}

//set device to mute
private void setMute(final boolean isMute){
	AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
	am.setStreamMute(AudioManager.STREAM_MUSIC, isMute);
	//confirm device mute
	alexaManager.sendMutedEvent(isMute, requestCallback);
}

 private static void sendMediaButton(Context context, int keyCode) {
	KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
	Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
	intent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
	context.sendOrderedBroadcast(intent, null);

	keyEvent = new KeyEvent(KeyEvent.ACTION_UP, keyCode);
	intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
	intent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
	context.sendOrderedBroadcast(intent, null);
}

Recipes

Here's a quick overview of the code that will likely be required to create a solid application, check the JavaDoc for more details.

Logging In To Amazon

//Run an async check on whether we're logged in or not
alexaManager.checkLoggedIn(mLoggedInCheck);

//Check if the user is already logged in to their Amazon account
alexaManager.checkLoggedIn(AsyncCallback...);

//Log the user in
alexaManager.logIn(AuthorizationCallback...);

Send Live Audio (bonus: check for Record Audio permission)

private final static int MY_PERMISSIONS_REQUEST_RECORD_AUDIO = 1;
private static final int AUDIO_RATE = 16000;
private RawAudioRecorder recorder;
private RecorderView recorderView;

@Override
public void onResume() {
    super.onResume();

    //request API-23 permission for RECORD_AUDIO
    if (ContextCompat.checkSelfPermission(getActivity(),
            Manifest.permission.RECORD_AUDIO)
            != PackageManager.PERMISSION_GRANTED) {
        if (!ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
                Manifest.permission.RECORD_AUDIO)) {
            ActivityCompat.requestPermissions(getActivity(),
                    new String[]{Manifest.permission.RECORD_AUDIO},
                    MY_PERMISSIONS_REQUEST_RECORD_AUDIO);
        }
    }
}

//recieve RECORD_AUDIO permissions request
@Override
public void onRequestPermissionsResult(int requestCode,
                                       @NonNull String permissions[],
                                       @NonNull int[] grantResults) {
    switch (requestCode) {
        case MY_PERMISSIONS_REQUEST_RECORD_AUDIO: {
            // If request is cancelled, the result arrays are empty.
            if (!(grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED)){
                getActivity().getSupportFragmentManager().beginTransaction().remove(this).commit();
            }
        }

    }
}

@Override
public void onStop() {
    super.onStop();
    //tear down our recorder on stop
    if(recorder != null){
        recorder.stop();
        recorder.release();
        recorder = null;
    }
}

@Override
public void startListening() {
    if(recorder == null){
        recorder = new RawAudioRecorder(AUDIO_RATE);
    }
    recorder.start();
    alexaManager.sendAudioRequest(requestBody, getRequestCallback());
}

//our streaming data requestBody
private DataRequestBody requestBody = new DataRequestBody() {
    @Override
    public void writeTo(BufferedSink sink) throws IOException {
        //while our recorder is not null and it is still recording, keep writing to POST data
        while (recorder != null && !recorder.isPausing()) {
            if(recorder != null) {
                final float rmsdb = recorder.getRmsdb();
                if(recorderView != null) {
                    recorderView.post(new Runnable() {
                        @Override
                        public void run() {
                            recorderView.setRmsdbLevel(rmsdb);
                        }
                    });
                }
                if(sink != null && recorder != null) {
                    sink.write(recorder.consumeRecording());
                }
            }

            //sleep and do it all over again
            try {
                Thread.sleep(25);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        stopListening();
    }

};

//tear down our recorder
private void stopListening(){
    if(recorder != null) {
        recorder.stop();
        recorder.release();
        recorder = null;
    }
}

Send Prerecorded Audio

//send prerecorded audio to Alexa, parse the callback in requestCallback
try {
    //open asset file
    InputStream is = getActivity().getAssets().open("intros/joke.raw");
    byte[] fileBytes=new byte[is.available()];
    is.read(fileBytes);
    is.close();
    mAlexaManager.sendAudioRequest(fileBytes, getRequestCallback());
} catch (IOException e) {
    e.printStackTrace();
}

Send Text Request

//send a text request to Alexa, parse the callback in requestCallback
mAlexaManager.sendTextRequest(text, requestCallback);

Play Returned Content

//Play an AvsPlayItem returned by our requests
audioPlayer.playItem(AvsPlayAudioItem...);

//Play an AvsSpeakItem returned by our requests
audioPlayer.playItem(AvsSpeakItem...);

Everything Else

Let me know if you would like to contribute to this library!

Thanks

Josh for MP3 work

alexaandroid's People

Contributors

ikurtchen avatar jorgesilva avatar kushtrimpacaj avatar nangsan avatar quangson91 avatar wblaschkovf avatar willblaschko avatar y-yagi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alexaandroid's Issues

Can't play for AvsPlayRemoteItem response.

Your code is working well. But when I speak " What's in the news?", there are AvsPlayRemoteItem response after SpeakItem. The audio player can't play the media from url which is contained in the AvsPlayRemoteItem response.

How can I play that?

android 4.4.2 not work

hi, I found that this code run on android4.4.2 had some problems, it would be error in handshake. log as below:
javax.net.ssl.SSLException: Connection closed by peer
08-24 15:20:43.661 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
08-24 15:20:43.671 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:406)
08-24 15:20:43.806 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at okhttp3.internal.io.RealConnection.connectTls(RealConnection.java:239)
08-24 15:20:44.171 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at okhttp3.internal.io.RealConnection.establishProtocol(RealConnection.java:196)
08-24 15:20:44.246 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at okhttp3.internal.io.RealConnection.buildConnection(RealConnection.java:171)
08-24 15:20:44.401 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at okhttp3.internal.io.RealConnection.connect(RealConnection.java:111)
08-24 15:20:44.451 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:187)
08-24 15:20:44.451 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:123)
08-24 15:20:44.456 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:93)
08-24 15:20:44.456 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:296)
08-24 15:20:44.466 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
08-24 15:20:44.466 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at okhttp3.RealCall.getResponse(RealCall.java:243)
08-24 15:20:44.471 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201)
08-24 15:20:44.471 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163)
08-24 15:20:44.481 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at okhttp3.RealCall.execute(RealCall.java:57)
08-24 15:20:44.486 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at com.willblaschko.android.alexa.interfaces.SendEvent.parseResponse(SendEvent.java:85)
08-24 15:20:44.486 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at com.willblaschko.android.alexa.interfaces.SendEvent.completePost(SendEvent.java:75)
08-24 15:20:44.486 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at com.willblaschko.android.alexa.interfaces.GenericSendEvent.(GenericSendEvent.java:30)
08-24 15:20:44.501 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at com.willblaschko.android.alexa.AlexaManager$9$1$1.doInBackground(AlexaManager.java:717)
08-24 15:20:44.541 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at com.willblaschko.android.alexa.AlexaManager$9$1$1.doInBackground(AlexaManager.java:714)
08-24 15:20:44.596 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288)
08-24 15:20:44.596 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
08-24 15:20:44.596 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
08-24 15:20:44.821 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
08-24 15:20:44.861 11425-11786/com.willblaschko.android.alexavoicelibrary W/System.err: at java.lang.Thread.run(Thread.java:841)

APIKey is incorrect or does not exist

Hello,

I have changed the product ID after creating an application on my amazon account. I keep getting the error "APIKey is incorrect or does not exist".

Please help. Thanks

MediaPlayer

I'm having a hard time to play iHeartRadio (or any other streaming music for that matter). it seems that mediaplayer gives an error on prepare().
are you familiar with such issue?

Uri.

no audio response from AVS

Hi,
first - thanks a lot for your contribution!
I was able to build and deploy your project, but i wasn't able to get any audio response although i'm able to see that the audio is being sent to AVS.
are you familiar with such issue?
could it be that I missed some response in the past and it somehow went out of synchronization?

thanks in advance,
Uri.

How can I recude the delay between startListening() and requestbody()?

When I pressed mic button to send audio data to alexa server, there is a delay about 1.5 sec.
I added two debug log message startListening() and reqeustbody() like below.
The real pcm audio data is sent to the server using sinkWrite().
But the first audio data is sent to the server after 1.5 sec when I pressed button.
The time gap between two debug messages is about 1.5 sec.
How can I reduce this delay?

I'll put the source code to show where I added log messages and adb log message to show timestamp.

@OverRide public void startListening() { Log.d(TAG, "start to alexa avs"); // Here is 1st message if(recorder == null){ recorder = new RawAudioRecorder(AUDIO_RATE); } recorder.start(); alexaManager.sendAudioRequest(requestBody, getRequestCallback()); }
private DataRequestBody requestBody = new DataRequestBody() {
    @Override
    public void writeTo(BufferedSink sink) throws IOException {

        Log.d(TAG, "requestBody is run....."); // Here is 2nd message
        while (recorder != null && !recorder.isPausing()) {
            if(recorder != null) {
                final float rmsdb = recorder.getRmsdb();
                if(recorderView != null) {
                    recorderView.post(new Runnable() {
                        @Override
                        public void run() {
                            recorderView.setRmsdbLevel(rmsdb);
                        }
                    });
                }
                if(sink != null && recorder != null) {
                    sink.write(recorder.consumeRecording());
                }
                if(BuildConfig.DEBUG){
                    Log.i(TAG, "Received audio");
                    Log.i(TAG, "RMSDB: " + rmsdb);
                }
            }

21:36:53.481, 21:36:54.722
12-07 21:36:53.481 15979-15979/com.willblaschko.android.alexavoicelibrary D/SendAudioActionFragment: start to alexa avs
12-07 21:36:53.482 15979-15979/com.willblaschko.android.alexavoicelibrary V/AudioRecord: set(): inputSource 6, sampleRate 16000, format 0x1, channelMask 0x10, frameCount 2560, notificationFrames 0, sessionId 0, transferType 0, flags 0
12-07 21:36:53.482 15979-15979/com.willblaschko.android.alexavoicelibrary V/AudioRecord: set(): mSessionId 14191
12-07 21:36:53.486 15979-15996/com.willblaschko.android.alexavoicelibrary V/AudioSystem: ioConfigChanged() event 3, ioHandle 14192
12-07 21:36:53.498 15979-15979/com.willblaschko.android.alexavoicelibrary V/AudioRecord: start, sync event 0 trigger session 0
12-07 21:36:53.498 15979-15979/com.willblaschko.android.alexavoicelibrary V/AudioRecord: mAudioRecord->start()
12-07 21:36:53.516 15979-17115/com.willblaschko.android.alexavoicelibrary I/BaseActivity: Event Start
12-07 21:36:53.518 15979-17115/com.willblaschko.android.alexavoicelibrary I/SpeechSendAudio: Starting SpeechSendAudio procedure
12-07 21:36:53.553 15979-17115/com.willblaschko.android.alexavoicelibrary D/libc-netbsd: [getaddrinfo]: hostname=avs-alexa-na.amazon.com; servname=(null); cache_mode=(null), netid=0; mark=0
12-07 21:36:53.553 15979-17115/com.willblaschko.android.alexavoicelibrary D/libc-netbsd: [getaddrinfo]: ai_addrlen=0; ai_canonname=(null); ai_flags=4; ai_family=0
12-07 21:36:53.554 15979-17115/com.willblaschko.android.alexavoicelibrary D/libc-netbsd: [getaddrinfo]: hostname=avs-alexa-na.amazon.com; servname=(null); cache_mode=(null), netid=0; mark=0
12-07 21:36:53.554 15979-17115/com.willblaschko.android.alexavoicelibrary D/libc-netbsd: [getaddrinfo]: ai_addrlen=0; ai_canonname=(null); ai_flags=1024; ai_family=0
12-07 21:36:53.564 15979-17115/com.willblaschko.android.alexavoicelibrary I/System.out: propertyValue:false
12-07 21:36:53.588 15979-17115/com.willblaschko.android.alexavoicelibrary D/libc-netbsd: [getaddrinfo]: hostname=avs-alexa-na.amazon.com; servname=(null); cache_mode=(null), netid=0; mark=0
12-07 21:36:53.588 15979-17115/com.willblaschko.android.alexavoicelibrary D/libc-netbsd: [getaddrinfo]: ai_addrlen=0; ai_canonname=(null); ai_flags=4; ai_family=0
12-07 21:36:54.722 15979-17115/com.willblaschko.android.alexavoicelibrary D/SendAudioActionFragment: requestBody is run.....
12-07 21:36:54.728 15979-17115/com.willblaschko.android.alexavoicelibrary I/SendAudioActionFragment: Received audio

[Question]About OKHttp 'the Connection Reset By Peer' issue

Thanks for your awesome work! I noticed this comment from your code:
/**

  • Create a singleton OkHttp client that, hopefully, will someday be able to make sure all connections are valid according to AVS's strict
  • security policy--this will hopefully fix the Connection Reset By Peer issue.
    *
  • Created by willb_000 on 6/26/2016.
    */

So when does this problem happen? what's the consequences of OKHttp Connection Reset By Peer issue? Amazon recommends three http2 library: OKHTTP, Jetty and Netty. If it's a severe problem, should I consider using an alternate? How can I make sure the other 2 libs do not have same issue?

appreciate your suggestion.

Live streaming of voice

I have not tried your solution just curious to know does your Alexa android app supports live streaming of voice and have capability of bidirectional streaming with low latency.

LWA SDK update

The LWA for Android library has since updated, with major changes.

Lattest ZIP available here

No parameter to set scope..for authorization manager

The default scope given is alexa:all. It seems logical to expose the scope functionality through the alexa manager, or the authorization manager.

For example in my application I also use the "profile" scope to get the users amazon id. I should be able to do it via setting a scope parameter in the initializer, or authorize function.

Question regarding a time when start application.

When I start your application, it takes about 10 seconds to start to run.
It takes always about 10 seconds to start application.
What happen to application to run? How can I reduce initial time to run?

11-02 16:54:56.640 27178-27178/? I/InstantRun: Instant Run Runtime started. Android package is com.willblaschko.android.alexavoicelibrary, real application class is com.willblaschko.android.alexavoicelibrary.AlexaApplication.
11-02 16:55:06.040 27178-27178/com.willblaschko.android.alexavoicelibrary I/AlexaApplication: <FingerPrint>

SSLException:Connection closed by peer.SSL_do_handshake on Android4.4.2

sir:
I run the source code on device Android4.4.2
I got this SSLException in OpenDownchannel.java connect(){response = currentCall.execute();}. the whole stackview is in the end.
I am already try the CustomSslSocketFactory.java on the Internet,key word is "setEnabledProtocols(TLSv1.2)" and also try NativeCrypto.setEnabledProtocols(sslNativePointer, "TLSv1.2");,the error also apperaed. someone help me?thank you.

12-20 11:15:48.418 E/NativeCrypto( 1726): SESTEP jni Unknown error SSL_ERROR_SYSCALL during handshake
12-20 11:15:48.428 W/System.err( 1726): javax.net.ssl.SSLException: Connection closed by peer
12-20 11:15:48.428 W/System.err( 1726): at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
12-20 11:15:48.428 W/System.err( 1726): at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:439)
12-20 11:15:48.428 W/System.err( 1726): at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:241)
12-20 11:15:48.428 W/System.err( 1726): at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:198)
12-20 11:15:48.438 W/System.err( 1726): at okhttp3.internal.connection.RealConnection.buildConnection(RealConnection.java:174)
12-20 11:15:48.438 W/System.err( 1726): at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:114)
12-20 11:15:48.438 W/System.err( 1726): at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:193)
12-20 11:15:48.438 W/System.err( 1726): at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:129)
12-20 11:15:48.438 W/System.err( 1726): at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:98)
12-20 11:15:48.438 W/System.err( 1726): at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
12-20 11:15:48.438 W/System.err( 1726): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
12-20 11:15:48.438 W/System.err( 1726): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
12-20 11:15:48.438 W/System.err( 1726): at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:109)
12-20 11:15:48.448 W/System.err( 1726): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
12-20 11:15:48.448 W/System.err( 1726): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
12-20 11:15:48.458 W/System.err( 1726): at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
12-20 11:15:48.458 W/System.err( 1726): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
12-20 11:15:48.458 W/System.err( 1726): at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:124)
12-20 11:15:48.458 W/System.err( 1726): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
12-20 11:15:48.458 W/System.err( 1726): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
12-20 11:15:48.458 W/System.err( 1726): at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170)
12-20 11:15:48.458 W/System.err( 1726): at okhttp3.RealCall.execute(RealCall.java:60)
12-20 11:15:48.458 W/System.err( 1726): at com.willblaschko.android.alexa.interfaces.system.OpenDownchannel.connect(OpenDownchannel.java:65)
12-20 11:15:48.458 W/System.err( 1726): at com.willblaschko.android.alexa.AlexaManager$5$1$1.doInBackground(AlexaManager.java:222)
12-20 11:15:48.458 W/System.err( 1726): at com.willblaschko.android.alexa.AlexaManager$5$1$1.doInBackground(AlexaManager.java:1)
12-20 11:15:48.458 W/System.err( 1726): at android.os.AsyncTask$2.call(AsyncTask.java:288)
12-20 11:15:48.458 W/System.err( 1726): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
12-20 11:15:48.458 W/System.err( 1726): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
12-20 11:15:48.458 W/System.err( 1726): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
12-20 11:15:48.458 W/System.err( 1726): at java.lang.Thread.run(Thread.java:841)
12-20 11:15:48.468 I/BaseActivity( 1726): Event Error
12-20 11:15:48.468 I/BaseActivity( 1726): Event Complete

Facing problem with APIKey decoding

Hi Will,

Thank you for sharing this. Great Job.
I'm facing some difficulty while running this app in my android studio. I crossed check your given instructions couple of times but don't know what I'm missing. The problem is with APIKey decoding.
Can you please help me with this.

Thanks!
RohitW
06-20 18:08:15.035 9975-9975/com.willblaschko.android.alexavoicelibrary W/com.amazon.identity.auth.device.appid.APIKeyDecoder: Failed to decode: Decoding failed: certificate fingerprint can't be verified! pkg=com.willblaschko.android.alexavoicelibrary 06-20 18:08:15.035 9975-9975/com.willblaschko.android.alexavoicelibrary W/com.amazon.identity.auth.device.appid.APIKeyDecoder: Unable to decode APIKey for pkg=com.willblaschko.android.alexavoicelibrary 06-20 18:08:15.037 9975-9975/com.willblaschko.android.alexavoicelibrary E/AuthorizationHandler: Unable to Use Amazon Authorization Manager. APIKey is incorrect or does not exist. Does assets/api_key.txt exist in the main application? 06-20 18:08:15.037 9975-9975/com.willblaschko.android.alexavoicelibrary E/AuthorizationHandler: java.lang.IllegalArgumentException: Invalid API Key 06-20 18:08:15.037 9975-9975/com.willblaschko.android.alexavoicelibrary E/AuthorizationHandler: at com.amazon.identity.auth.device.authorization.api.AmazonAuthorizationManager.<init>(AmazonAuthorizationManager.java:133) 06-20 18:08:15.037 9975-9975/com.willblaschko.android.alexavoicelibrary E/AuthorizationHandler: at com.willblaschko.android.alexa.AuthorizationManager.<init>(AuthorizationManager.java:55) 06-20 18:08:15.037 9975-9975/com.willblaschko.android.alexavoicelibrary E/AuthorizationHandler: at com.willblaschko.android.alexa.AlexaManager.<init>(AlexaManager.java:47) 06-20 18:08:15.037 9975-9975/com.willblaschko.android.alexavoicelibrary E/AuthorizationHandler: at com.willblaschko.android.alexa.AlexaManager.getInstance(AlexaManager.java:53) 06-20 18:08:15.037 9975-9975/com.willblaschko.android.alexavoicelibrary E/AuthorizationHandler: at com.willblaschko.android.alexavoicelibrary.BaseActivity.initAlexaAndroid(BaseActivity.java:98) 06-20 18:08:15.037 9975-9975/com.willblaschko.android.alexavoicelibrary E/AuthorizationHandler: at com.willblaschko.android.alexavoicelibrary.BaseActivity.onCreate(BaseActivity.java:65) 06-20 18:08:15.037 9975-9975/com.willblaschko.android.alexavoicelibrary E/AuthorizationHandler: at com.willblaschko.android.alexavoicelibrary.MainActivity.onCreate(MainActivity.java:30) 06-20 18:08:15.037 9975-9975/com.willblaschko.android.alexavoicelibrary E/AuthorizationHandler: at android.app.Activity.performCreate(Activity.java:6010) 06-20 18:08:15.037 9975-9975/com.willblaschko.android.alexavoicelibrary E/AuthorizationHandler: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129) 06-20 18:08:15.037 9975-9975/com.willblaschko.android.alexavoicelibrary E/AuthorizationHandler: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292) 06-20 18:08:15.037 9975-9975/com.willblaschko.android.alexavoicelibrary E/AuthorizationHandler: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413) 06-20 18:08:15.037 9975-9975/com.willblaschko.android.alexavoicelibrary E/AuthorizationHandler: at android.app.ActivityThread.access$800(ActivityThread.java:155) 06-20 18:08:15.037 9975-9975/com.willblaschko.android.alexavoicelibrary E/AuthorizationHandler: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)

Alexa Voice Service

Awesome example, thanks very much for this!. Amazon documentation is really tough to digest, so this is super helpful.
I was wondering if you have considered using Alexa Voice Service? Is there any reason to use Google Speach Recognition engine instead of Alexa's?

crash application when TextToSpeech not intialized

If I init alexaManager then call alexaManager.sendTextRequest(query, requestCallback); intermediately -> application will be crash. Logcat show exception: IllegalStateException("Unable to initialize Text to Speech engine"). So I think we must handler all exception.

error of the latest version

hi, when i use the latest version, there is a errror when start:
1
and when i comment out alexaManager.sendSynchronizeStateEvent(requestCallback); in BaseActivity, there are more errors.

Timeout

Hello there,

I'm using your library and works very well, but I'm getting a timeout multiple times after the first usage.
Is any thing that I could do?

Thanks!

Alarm and Timer not working

I am not able to set alarm or timer.
If I try to set an alarm, I get this response : "Sorry there is a problem setting your alarm".
If I set a timer say for 30 sec, I don't get any alert after 30 sec.

What might be the issue??? Please Help...
Thank You...

PS: I am using your application outside US.

I can't find the apk in this app

Hi all,

I download this sample app, when I use android studio2.1.3 to open it, it shows :
Error:(7, 0) Unable to find signing.gradle, please replace Android buildTypes > signing configs with your own configuration.
I think I need to add api_key.txt before run.
But if I need to get the api_key.txt file ,I need to find the apk to get the SHA-256 or MD5 value to generate the api key on these 2 webpages https://sellercentral.amazon.com/ or https://developer.amazon.com/avs/home.html#/

Who can give me some advice?

Thank you!

Do I need to change the android package name when I compile for my Amazon account for test?

Hi,

I have successfully compile this library by android studio.
But when I run the app on my device, I have encountered amzaon LWA problem.
I could run the sample app download from Android Play and work with alexa on it.
But when I run my compile apk, it stucked on the LWA.
For these 2 test, I use the same amazon account.
I have carefully checked with the API-keys with that on the Amazon Developer site.

I just wonder I need to change the package name, "com.willblaschko.android.alexavoicelibrary" to another specific one when I make the api-key on Amazon.developer.com and compile the android studio project.

Any suggestion?
Thank you very much for your great help.

Best Regards'
Stephen Lau

Alexa voice service version

Hello,
First of all thank you very much for this amazing sample for alexa voice service. It helped me a lot to understand how actually alexa voice service is working.
I'm not very sure but by looking at your code It seems like you are using AVS V1 but now there is a new version of AVS v20160207.

I'm a bit confused in migrating from v1 to new version. Can you please guide me or if possible update your sample to make things clear.

Sorry for my bad english.
Thanks.

Popup Dialog in each request

hi, every time i send a request to AVS and play back the response audio. After that, there will be a dialog:
12
it should be the response of AVS to PlaybackNearlyFinishedEvent.
i had submitted a pull request for that, sorry to cause other error: fix speak items not triggering finished event.
so what is the fundamental solution?
thanks very much,best regards for you!

handing alexa directive

Hi,
I got an message from Alexa Team:

The Alexa Voice Service (AVS) is continually being updated with new features to offer the best experience for Alexa users. Some of these features may result in the transmission of new directives or new properties in the JSON response payload. We will maintain backward compatibility with the existing directives and properties, but your code may need to be updated to be resilient to such additions. Please refer to the following files in the AVS Sample App for relevant code examples:

Handling directives
AVSController.java: Refer to the dispatch function. Note that you should send an ExceptionEncountered event to Alexa if your client receives an unknown directive.
Processing JSON payloads
Message.java: Refer to the MessageDeserializer function.
ObjectMapperFactory.java: Note the setting of FAIL_ON_UNKNOWN_PROPERTIES to FALSE.
If changes are required to your code to be resilient to new directives and JSON payloads, you must complete these changes by Dec. 1, 2016.

So is the library update it ?

Thanks !

Request for example of signing.gradle configuration.

I cloned these code and opened source code with Android studio.
There is a error message like "Unable to find signing.gradle, please replace Android buildTypes > signing configs with your own configuration".
But I need your help to resolve error. Could you show me a sample configuration for signing.gradle?

authorization failed issue

c6903ab6-4a9e-11e6-9c65-0a5a1b1f048e

Tnx for the code and I am trying to compile and test the app. But I am getting an error right after I press I agree.

Alexa library Support for Linux.

Does your Alexa library can be used for Linux Platform also? If yes what is the changes we need to do.
? Any suggestion would be of great help.

No response when trying to send Text Request

Hello there,
I successfully logged in and get the Access Token. But, when trying to send Text Request, it gets stuck and has no response. Then, I found that it doesn't have callback in SendText.java > voiceHelper.getSpeechFromText(...) which means that it'll not run completePost() send the request to Alexa server.
Do anyone know how to solve the problem?
Any help is greatly appreciated!

I met error in android 4.4.4 "System.err: javax.net.ssl.SSLException: Connection closed by peer "

System.err: javax.net.ssl.SSLException: Connection closed by peer
System.err: at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:405)
System.err: at okhttp3.internal.io.RealConnection.connectTls(RealConnection.java:239)
System.err: at okhttp3.internal.io.RealConnection.establishProtocol(RealConnection.java:196)

Getting auth issue form Amazon

Hi Guys,

I am getting following issue from amazon after asking for permission,

screenshot_2016-05-30-10-38-22 1

I have entered Product_ID,api_key correctly

This is kind request to help me to resolve this issue .

No response after 2-3 tries, need to exit the app to recover.

I am using Nexus 5, Marshmallow. Downloaded the apk. I see it works good for 2-3 consecutive tries when I ask questions(Send Audio and not prerecorded). But after that I don't get any response. I see following exception in the log: What possibly is going wrong here?

08-24 16:51:17.696 23814-24573/? W/System.err: java.io.IOException: stream was reset: CANCEL
08-24 16:51:17.696 23814-24573/? W/System.err: at okhttp3.internal.framed.FramedStream.checkOutNotClosed(FramedStream.java:574)
08-24 16:51:17.696 23814-24573/? W/System.err: at okhttp3.internal.framed.FramedStream.access$1200(FramedStream.java:34)
08-24 16:51:17.696 23814-24573/? W/System.err: at okhttp3.internal.framed.FramedStream$FramedDataSink.emitDataFrame(FramedStream.java:508)
08-24 16:51:17.696 23814-24573/? W/System.err: at okhttp3.internal.framed.FramedStream$FramedDataSink.write(FramedStream.java:488)
08-24 16:51:17.696 23814-24573/? W/System.err: at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)
08-24 16:51:17.696 23814-24573/? W/System.err: at okio.RealBufferedSink.write(RealBufferedSink.java:90)
08-24 16:51:17.699 23814-24573/? W/System.err: at com.willblaschko.android.alexavoicelibrary.actions.SendAudioActionFragment$2.writeTo(SendAudioActionFragment.java:128)
08-24 16:51:17.699 23814-24573/? W/System.err: at okhttp3.MultipartBody.writeOrCountBytes(MultipartBody.java:171)
08-24 16:51:17.699 23814-24573/? W/System.err: at okhttp3.MultipartBody.writeTo(MultipartBody.java:113)
08-24 16:51:17.699 23814-24573/? W/System.err: at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:704)
08-24 16:51:17.699 23814-24573/? W/System.err: at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:563)
08-24 16:51:17.699 23814-24573/? W/System.err: at okhttp3.RealCall.getResponse(RealCall.java:241)
08-24 16:51:17.704 23814-24573/? W/System.err: at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198)
08-24 16:51:17.704 23814-24573/? W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
08-24 16:51:17.705 23814-24573/? W/System.err: at okhttp3.RealCall.execute(RealCall.java:57)
08-24 16:51:17.705 23814-24573/? W/System.err: at com.willblaschko.android.alexa.interfaces.SendEvent.parseResponse(SendEvent.java:84)
08-24 16:51:17.705 23814-24573/? W/System.err: at com.willblaschko.android.alexa.interfaces.SendEvent.completePost(SendEvent.java:74)
08-24 16:51:17.705 23814-24573/? W/System.err: at com.willblaschko.android.alexa.interfaces.speechrecognizer.SpeechSendAudio.sendAudio(SpeechSendAudio.java:50)
08-24 16:51:17.707 23814-24573/? W/System.err: at com.willblaschko.android.alexa.AlexaManager$9$1$1.doInBackground(AlexaManager.java:623)
08-24 16:51:17.707 23814-24573/? W/System.err: at com.willblaschko.android.alexa.AlexaManager$9$1$1.doInBackground(AlexaManager.java:619)
08-24 16:51:17.707 23814-24573/? W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:295)
08-24 16:51:17.707 23814-24573/? W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
08-24 16:51:17.707 23814-24573/? W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
08-24 16:51:17.707 23814-24573/? W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
08-24 16:51:17.707 23814-24573/? W/System.err: at java.lang.Thread.run(Thread.java:818)
08-24 16:51:17.707 23814-24573/? I/BaseActivity: Voice Error
08-24 16:51:17.707 23814-24573/? I/BaseActivity: Voice Complete
08-24 16:51:17.724 23814-23814/? I/BaseActivity: Total request time: 11026 miliseconds

I used AlexaAndroid library with my app, and I see similar issue. Exactly after 2 tries I get error while sending event due to below error. What am I missing here? Any help really appreciated.

08-24 16:39:02.714 22539-22699/? W/System.err: java.net.SocketTimeoutException: timeout
08-24 16:39:02.715 22539-22699/? W/System.err: at okhttp3.internal.framed.FramedStream$StreamTimeout.newTimeoutException(FramedStream.java:600)
08-24 16:39:02.715 22539-22699/? W/System.err: at okhttp3.internal.framed.FramedStream$StreamTimeout.exitAndThrowIfTimedOut(FramedStream.java:608)
08-24 16:39:02.715 22539-22699/? W/System.err: at okhttp3.internal.framed.FramedStream$FramedDataSource.waitUntilReadable(FramedStream.java:379)
08-24 16:39:02.715 22539-22699/? W/System.err: at okhttp3.internal.framed.FramedStream$FramedDataSource.read(FramedStream.java:342)
08-24 16:39:02.716 22539-22699/? W/System.err: at okio.ForwardingSource.read(ForwardingSource.java:35)
08-24 16:39:02.716 22539-22699/? W/System.err: at okio.RealBufferedSource$1.read(RealBufferedSource.java:409)
08-24 16:39:02.716 22539-22699/? W/System.err: at java.io.InputStream.read(InputStream.java:162)
08-24 16:39:02.716 22539-22699/? W/System.err: at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1025)
08-24 16:39:02.716 22539-22699/? W/System.err: at org.apache.commons.io.IOUtils.copy(IOUtils.java:999)
08-24 16:39:02.716 22539-22699/? W/System.err: at org.apache.commons.io.IOUtils.toByteArray(IOUtils.java:218)
08-24 16:39:02.717 22539-22699/? W/System.err: at com.knowles.alexalibrary.interfaces.response.ResponseParser.parseResponse(ResponseParser.java:70)
08-24 16:39:02.717 22539-22699/? W/System.err: at com.knowles.alexalibrary.interfaces.SendEvent.parseResponse(SendEvent.java:100)
08-24 16:39:02.717 22539-22699/? W/System.err: at com.knowles.alexalibrary.interfaces.SendEvent.completePost(SendEvent.java:75)
08-24 16:39:02.717 22539-22699/? W/System.err: at com.knowles.alexalibrary.interfaces.speechrecognizer.SpeechSendAudio.sendAudio(SpeechSendAudio.java:50)
08-24 16:39:02.717 22539-22699/? W/System.err: at com.knowles.alexalibrary.AlexaManager$8$1$1.doInBackground(AlexaManager.java:578)
08-24 16:39:02.717 22539-22699/? W/System.err: at com.knowles.alexalibrary.AlexaManager$8$1$1.doInBackground(AlexaManager.java:574)
08-24 16:39:02.718 22539-22699/? W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:295)
08-24 16:39:02.718 22539-22699/? W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
08-24 16:39:02.718 22539-22699/? W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
08-24 16:39:02.718 22539-22699/? W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
08-24 16:39:02.718 22539-22699/? W/System.err: at java.lang.Thread.run(Thread.java:818)

'com.google.android.gms:play-services:9.4.+' whole api needed?

In the AlexaAndroid/libs/AlexaAndroid/build.gradle file I noticed you include the entire Google play-services api. is it possible for you to reduce this to only the play-service API's needed? I suspect this dependency is causing the need for multidex (as it has caused for me in the past). I noticed this when I was adding Firebase to my project and it informed me that i had duplicates. Otherwise great job on this library, really useful!

https://developers.google.com/android/guides/setup

Device not compatible on Google Play

I have distributed APK for beta Testing on Google Play. Testers reporting that they are not able to install the App as Device not compatible.

Make path of audio file in callback

Currently, we storage audio file in cache folder; but each request we storage in one file:

File path=new File(mContext.getCacheDir(), System.currentTimeMillis()+".mp3");

So I think we could add callback to know the path of file; Also, for storage problem -> I think we need limit number of file;

Login and authentication problem.

Thanks for your sharing code for android alexa application.
I download your source code and rename package name to com.hci.mobilealexa.
I also create api key and put it asset folder and modify PRODUCT_ID in source code.

When I try to execute my application, popup windows is displayed titled "complete action using". So I selected "Alexa Voice Library". After that white empty window is shown and disappeared.
I can't see the login page.
How can I solve this problem?

p.s. I downloaded your application in playstore and confirmed your application is working.

Signing Problem

Hi Will,

I'm stuck, could you help me please?
I regsitered an AVS-App with Amazon and extracted the MD5 of the certificate of the release-build APK of your sample app (using own test-keystore) with keytool like described in the Amzn documentation (can't find the link right now), but the app crashes because the fingerprint doesn't seem to match :(

I/com.amazon.identity.auth.device.appid.APIKeyDecoder: Begin decoding API Key for packageName=com.willblaschko.android.alexavoicelibrary
I/com.amazon.identity.auth.device.appid.APIKeyDecoder: getKeyParts for packageName=com.willblaschko.android.alexavoicelibrary
D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII: APIKey:<obscured>
I/com.amazon.identity.auth.device.appid.APIKeyDecoder: verifySignature for packageName=com.willblaschko.android.alexavoicelibrary
I/com.amazon.identity.auth.device.appid.APIKeyDecoder: verifySignature Sha256 for packageName=com.willblaschko.android.alexavoicelibrary
I/com.amazon.identity.auth.device.appid.APIKeyDecoder: verifyPayload for packageName=com.willblaschko.android.alexavoicelibrary
D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII: Signature checking.:<obscured>
I/com.amazon.identity.auth.device.appid.APIKeyDecoder: num sigs = 1
D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII: Fingerprint checking:<obscured>
I/com.amazon.identity.auth.device.appid.APIKeyDecoder:  num sigs = 1
D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII: Fingerpirints checking:<obscured>
W/com.amazon.identity.auth.device.appid.APIKeyDecoder: Failed to decode: Decoding fails: certificate fingerprint can't be verified! pkg=com.willblaschko.android.alexavoicelibrary
W/com.amazon.identity.auth.device.appid.APIKeyDecoder: Unable to decode APIKEy for pkg=com.willblaschko.android.alexavoicelibrary
E/AuthorizationHandler: Unable to Use Amazon Authorization Manager. APIKey is incorrect or does not exist. Does assets/api_key.txt exist in the main application?
                                                                                                java.lang.IllegalArgumentException: Invalid API Key
                                                                                                    at com.amazon.identity.auth.device.authorization.api.AmazonAuthorizationManager.<init>(AmazonAuthorizationManager.java:133)

in the app's build.gradle, I have

android {
...
signingConfigs {
        release {
            storeFile rootProject.file('debug.jks')
            keyAlias 'test'
            keyPassword 'test'
            storePassword 'test'
        }
    }

        buildTypes {
            debug{
                versionNameSuffix " Debug"
                minifyEnabled false
                shrinkResources true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                signingConfig signingConfigs.release
            }
            release {
                minifyEnabled false
                shrinkResources true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                signingConfig signingConfigs.release
            }
        }
...
}

Do you have an idea, what I may have screwed up? :)

Many thanks in advance,
Martin

Getting issue while connecting via (okhttp) HTTP2 protocol.

We have downloaded the AlexaAndroid app and tested the functionalities. While sending data to AVS server using okhttp library, we are getting below error :
INFO: ALPN callback dropped: SPDY and HTTP/2 are disabled. Is alpn-boot on the boot class path?
How

We have tried adding alpn-boot on the class path but still getting the same error. Kindly help us to add alpn-boot on the class path.

Detecting end of voice recording

I have had no success in having the app stop a recording event automatically when I am done speaking. I have to manually stop recording by hitting the microphone button again.

How to receive StopCapture Directive

First of all, thanks for your sharing your code.
I found that there are 3 kinds of ASR profile (CLOSE_TALK, NEAR_FIELD, FAR_FIELD).
And I can receive StopCapture directive from Alexa when I use a profile near_field or far_field.
So I modify SpeechRecognizer event from close_talk to near or far and remove the code that determines end of speech at client. (I guess that is recorder.isPausing())
After that, I run the program. but I can't any directives to stop recording. How can I receive that directive?

authorization failed

hi ! first of all, thank you for AlexaAndroid open srouce project.it really help me to understand how to use alexa. but when i do all steps your readme file writed,i still cannot run the demo app normally. i always failed on the login step.

hope you can help me,thanks very much,best regards for you!

my problem is i can not authorization successed.

image
image
image

follows are my config information and amazon's profile as readme file writed:

image

image

image

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.