This project is directly clone from
https://github.com/willblaschko/AlexaAndroid
# 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](https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/content/avs-api-overview).
## 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](https://play.google.com/store/apps/details?id=com.willblaschko.android.alexavoicelibrary)
#### 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](https://github.com/willblaschko/AlexaAndroid/blob/master/app/src/main/java/com/willblaschko/android/alexavoicelibrary/global/Constants.java#L8) 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](https://play.google.com/store/apps/details?id=com.willblaschko.android.alexalistens)
## Using the Library
Most of the library can be accessed through the [AlexaManager](http://willblaschko.github.io/AlexaAndroid/com/willblaschko/android/alexa/AlexaManager.html) and [AlexaAudioPlayer](http://willblaschko.github.io/AlexaAndroid/com/willblaschko/android/alexa/avs/AlexaAudioPlayer.html) classes, both of which are singletons.
### Installation
* Ensure you're pulling from jcenter() for your project (project-level build.gradle):
```java
buildscript {
repositories {
jcenter()
}
...
}
allprojects {
repositories {
jcenter()
}
}
```
* Add the library to your imports (application-level build.gradle):
```java
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](https://developer.amazon.com/public/apis/engage/login-with-amazon/docs/create_android_project.html)
* 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
```java
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_P
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
alexa android (6098个子文件)
+bARmApYCMD05IOfD1f7j05gNgo= 1.26MB
+bARmApYCMD05IOfD1f7j05gNgo= 1.26MB
2leWdO_k_Wa8f0vsYloDkmN4JIE= 1.4MB
2leWdO_k_Wa8f0vsYloDkmN4JIE= 1.4MB
3hFwhZF_aSCla9+FtuL8oztTlck= 2KB
3hFwhZF_aSCla9+FtuL8oztTlck= 2KB
3W77ahg8DP4qG_AAYFX5R5awf50= 115KB
3W77ahg8DP4qG_AAYFX5R5awf50= 115KB
4U0zv5eHJnD3Qr1_JrGTcMiHfw8= 166B
4U0zv5eHJnD3Qr1_JrGTcMiHfw8= 166B
64++d8DBWi9pdqXl6rBZbHqxvAY= 844KB
64++d8DBWi9pdqXl6rBZbHqxvAY= 661KB
71jevKRM0Ir5nVD2s3hDBkxz_MA= 71KB
71jevKRM0Ir5nVD2s3hDBkxz_MA= 71KB
7pE1U8KZ1C6zC2xh2qD805KBj2w= 7KB
7pE1U8KZ1C6zC2xh2qD805KBj2w= 7KB
7Ze1YTnbLJtpLSouI5SMIYkZfv0= 122KB
7Ze1YTnbLJtpLSouI5SMIYkZfv0= 122KB
8lMLwdAicefK0PXMSMVjVdCOSjo= 9KB
8lMLwdAicefK0PXMSMVjVdCOSjo= 9KB
_8pBf2jsAOX_dZd8ZDHvo8TnwYs= 2KB
_8pBf2jsAOX_dZd8ZDHvo8TnwYs= 2KB
AAGmRSnLz0F7clGUgw+QuxjjHE8= 49KB
AAGmRSnLz0F7clGUgw+QuxjjHE8= 49KB
IAvsService.aidl 552B
IActivity.aidl 185B
User.aidl 62B
resources-debug.ap_ 844KB
resources-debugAndroidTest.ap_ 740KB
resources-debug.ir.ap_ 734KB
resources-debugAndroidTest.ap_ 478KB
resources-debugAndroidTest.ap_ 348KB
resources-debugAndroidTest.ap_ 27KB
app-debug.apk 8.28MB
dependencies.apk 6.4MB
slice_3.apk 98KB
slice_0.apk 89KB
slice_2.apk 65KB
slice_4.apk 50KB
slice_9.apk 44KB
slice_1.apk 30KB
slice_8.apk 26KB
slice_5.apk 20KB
slice_6.apk 16KB
slice_7.apk 12KB
AZVk7zQyer8p2gA0tJ9pSK9heow= 373KB
AZVk7zQyer8p2gA0tJ9pSK9heow= 373KB
gradlew.bat 2KB
fileSnapshots.bin 6.53MB
classAnalysis.bin 6.2MB
jarAnalysis.bin 2.8MB
fileHashes.bin 1.46MB
taskHistory.bin 987KB
taskHistory.bin 189KB
taskJars.bin 32KB
resourceHashesCache.bin 25KB
last-build.bin 1B
built.bin 0B
bSLP3TLelAKMLYt23+4A7_Z44zA= 743KB
bSLP3TLelAKMLYt23+4A7_Z44zA= 743KB
bXyz7hSKc2AbOB_iGWdbKSslOBU= 67KB
bXyz7hSKc2AbOB_iGWdbKSslOBU= 67KB
c6ae6dd3670efed22c56435c2d1304ce21a63c 146B
BaseActivity.class 50KB
BaseActivity.class 50KB
R$styleable.class 43KB
R$styleable.class 43KB
R$styleable.class 43KB
R$styleable.class 43KB
MicButton.class 43KB
MicButton.class 43KB
R$styleable.class 42KB
R$styleable.class 42KB
R$styleable.class 42KB
R$styleable.class 42KB
RecorderView.class 41KB
RecorderView.class 41KB
MainActivity.class 39KB
MainActivity.class 39KB
LoginActivity.class 35KB
LoginActivity.class 35KB
SplashActivity.class 35KB
SplashActivity.class 35KB
R$styleable.class 32KB
R$styleable.class 32KB
R$styleable.class 32KB
R$styleable.class 32KB
LoginWebViewActivity.class 32KB
LoginWebViewActivity.class 32KB
R$styleable.class 27KB
R$styleable.class 27KB
R$style.class 27KB
R$style.class 27KB
R$style.class 24KB
R$style.class 24KB
R$style.class 24KB
R$style.class 24KB
R$style.class 24KB
R$style.class 24KB
R$style.class 24KB
共 6098 条
- 1
- 2
- 3
- 4
- 5
- 6
- 61
资源评论
放大的EZ
- 粉丝: 889
- 资源: 59
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功