Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,17 @@ google-services.json
freeline.py
freeline/
freeline_project_description.json

.idea/compiler.xml

.idea/copyright/profiles_settings.xml

.idea/encodings.xml

.idea/misc.xml

.idea/modules.xml

.idea/runConfigurations.xml

.idea/vcs.xml
77 changes: 3 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,8 @@
# DCS SDK(Java)开发者指南
基于DuerOS的自定义Android应用
基础代码来自https://github.com/dueros/dcs-sdk-java.git

## 声明

本开发指南为DuerOS Android DCS SDK v1.0的版本说明,该工程只做为dcs协议示例使用。本开源版本自2018-09-04起不再迭代维护。
从降低开发者接入成本、减少不可控问题出现的角度出发,DuerOS未来将主推SDK集成方案。

DuerOS DCS Android SDK v1.6.3.0及以后的版本将在百度DuerOS开放平台提供下载链接:
https://dueros.baidu.com/didp/doc/dueros-conversational-service/sdk_markdown

## DCS协议

DCS协议是DuerOS服务端与设备端之间的通讯协议,是一套把DuerOS的智能语音交互能力向所有设备开放的API,了解详情请看[DCS协议文档](http://developer.dueros.baidu.com/doc/dueros-conversational-service/introduction_markdown)。

## 摘要

DCS SDK提供DCS协议在设备端的实现,旨在降低设备接入DuerOS的开发成本。DCS SDK是完整的Sample App,可以直接在目标设备运行,并且源代码全部开源,开发者可以基于源码进行二次开发。

本文档介绍的DCS SDK(Java)是Java版本的实现,该版本目前支持Android系统。

## 1-前置条件

a.完成注册百度账号、开发者认证和产品创建(选择手机场景和Android平台)后,请保存client_id和client_secret

![](images/client-id-secret.png)

具体参考[控制台接入流程](http://developer.dueros.baidu.com/doc/overall/console-guide_markdown)。

b.在百度开发者中心配置OAuth的授权回调页
1. 到DuerOS开放平台控制台: https://dueros.baidu.com/didp/product/listview
2. 点击所创建产品的“编辑”按钮,按钮在右侧
3. 点击OAUTH CONFIG URL,到百度开发者平台控制台
4. 在开发者平台控制台,点击左侧“安全设置”
5. 在“授权回调页”输入框中输入"bdconnect://cancel,bdconnect://success"(不带双引号)
6. 点击页面下方“确定”按钮

c.开发环境
- Android Studio 2.2+
- Gradle 2.2+
- Android SDK 5.0+ (支持http/2)
- JDK 1.6+

## 2-克隆项目

```shell
git clone https://github.com/dueros/dcs-sdk-java.git
```

## 3-运行

a.通过Android Studio找到DcsSampleOAuthActivity.java,利用上述client_id进行替换

![](images/modify-client-id.png)

b.运行(Android真机)

![](images/login1.png)

c.百度账号登录

![](images/login2.png)

## 4-唤醒

说“小度小度”,成功唤醒后进入“录音中”状态,如下图:

![](images/wakeup.png)

## 5-和小度对话

a.通过唤醒或者单击“点击说话”进入录音状态, 问“北京天气怎么样”,DuerOS后端将发送stopListen指令,同时返回speak指令,播报北京天气。

b.问“播放刘若英的歌”, 返回play指令播放歌,可以从界面上进行“播放”、“暂停”、“上一首”和“下一首”操作。

## 6 SDK结构

#DuerOS代码及功能结构:
![](images/sdk-architecture.png)

![](images/access-architecture.png)
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
Expand Down Expand Up @@ -98,8 +99,8 @@ private void initView() {
webView.setWebViewClientListen(new BaseWebView.WebViewClientListener() {
@Override
public BaseWebView.LoadingWebStatus shouldOverrideUrlLoading(WebView view, String url) {
// 拦截处理不让其点击
return BaseWebView.LoadingWebStatus.STATUS_TRUE;
// 将值设为false后可点击
return BaseWebView.LoadingWebStatus.STATUS_FALSE;
}

@Override
Expand Down Expand Up @@ -406,4 +407,28 @@ protected void onDestroy() {
webView.removeAllViews();
webView.destroy();
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
if (webView.canGoBack()) {
webView.goBack();
return false;
} else {
moveTaskToBack(true);
}
}
return super.onKeyDown(keyCode, event);
}

@Override
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
return;
} else {
moveTaskToBack(true);
}
super.onBackPressed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.dcs_sample_activity_oauth);
initView();
setOnClickListener();
oauthLoginButton.callOnClick();
}

private void setOnClickListener() {
Expand Down
20 changes: 11 additions & 9 deletions app/src/main/res/layout/dcs_sample_activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
android:background="@color/color_f5f5f5"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/wakeup_word"
android:textColor="@android:color/black"
android:textSize="18dp" />
<!--<TextView-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center_horizontal"-->
<!--android:text="@string/wakeup_word"-->
<!--android:textColor="@android:color/black"-->
<!--android:textSize="18dp" />-->

<LinearLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -68,7 +68,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:textSize="16dp" />
android:textSize="16dp"
android:visibility="gone" />

<TextView
android:id="@+id/id_tv_RenderVoiceInputText"
Expand Down Expand Up @@ -103,7 +104,8 @@
android:background="@drawable/btn_bg"
android:text="@string/open_log"
android:textColor="@android:color/white"
android:textSize="16dp" />
android:textSize="16dp"
android:visibility="gone" />

</LinearLayout>

Expand Down
Binary file modified app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">DcsSampleApp</string>
<string name="app_name">Duer</string>
<string name="err_net_msg">当前网络连接失败,请稍后重试</string>
<string name="voice_err_msg">识别失败,请稍后再试</string>
<string name="audio_paused">暂停中&#8230;</string>
Expand Down
Binary file removed images/client-id-secret.png
Binary file not shown.
Binary file removed images/login1.png
Binary file not shown.
Binary file removed images/login2.png
Binary file not shown.
Binary file removed images/modify-client-id.png
Binary file not shown.
Binary file removed images/project.png
Binary file not shown.
Binary file removed images/wakeup.png
Binary file not shown.