极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

楼主: pz_cloud

自己做的智能家居终端Smaster~~带安卓客户端哦~有视频

  [复制链接]
发表于 2013-12-18 00:02:20 | 显示全部楼层
本帖最后由 闽海 于 2013-12-18 00:03 编辑

/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.android.apis.app;

import com.example.android.apis.R;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

/**
* Sample code that invokes the speech recognition intent API.
*/
public class VoiceRecognition extends Activity implements OnClickListener {
   
    private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
   
    private ListView mList;

    /**
     * Called with the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Inflate our UI from its XML layout description.
        setContentView(R.layout.voice_recognition);

        // Get display items for later interaction
        Button speakButton = (Button) findViewById(R.id.btn_speak);
        
        mList = (ListView) findViewById(R.id.list);

        // Check to see if a recognition activity is present
        PackageManager pm = getPackageManager();
        List<ResolveInfo> activities = pm.queryIntentActivities(
                new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
        if (activities.size() != 0) {
            speakButton.setOnClickListener(this);
        } else {
            speakButton.setEnabled(false);
            speakButton.setText("Recognizer not present");
        }
    }

    /**
     * Handle the click on the start recognition button.
     */
    public void onClick(View v) {
        if (v.getId() == R.id.btn_speak) {
            startVoiceRecognitionActivity();
        }
    }

    /**
     * Fire an intent to start the speech recognition activity.
     */
    private void startVoiceRecognitionActivity() {
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
        startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
    }

    /**
     * Handle the results from the recognition activity.
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
            // Fill the list view with the strings the recognizer thought it could have heard
            ArrayList<String> matches = data.getStringArrayListExtra(
                    RecognizerIntent.EXTRA_RESULTS);
            mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                    matches));
        }

        super.onActivityResult(requestCode, resultCode, data);
    }
}
回复 支持 反对

使用道具 举报

发表于 2013-12-18 00:56:13 | 显示全部楼层
pz_cloud 发表于 2013-12-17 23:51
不贵的~~主要成本就是那个路由

呵呵,有没有拓扑图可以看看呢...
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-12-18 10:40:02 | 显示全部楼层
闽海 发表于 2013-12-18 00:02
/*
* Copyright (C) 2008 The Android Open Source Project
*

有几点,首先你的手机要安装了语音搜索软件,比如自带的谷歌搜索,然后如果你手机版本在4.1以下的话,只能联网获取语音信息,4.1及以上可以离线,当然准确度联网要高很多。然后用你上面的api,获取到的结果会以一系列可能的结果的形式返回到一个字符串数组里,也就是你代码里那个matches里面,引用数组第一个元素就行了。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-12-18 10:41:06 | 显示全部楼层
laofuz1024 发表于 2013-12-18 00:56
呵呵,有没有拓扑图可以看看呢...

没画那种东西。。。结构不复杂的啊
回复 支持 反对

使用道具 举报

发表于 2013-12-18 12:01:33 | 显示全部楼层
谢谢LZ,一一作答。
基本理解了硬件的构架。实际上,这个改造的路由,就是做了ARDUINO上的wifi模块。这个确实,性价比太高了,wifi要300多了吧?我原本以为这路有起双重作用。
LZ能否好人做到底,把这个路有盒子内的各板子的连接,详细展示下?我这种硬件小白不少吧,大家受益。wifi模块实在太贵了,这个方案,大家都可以用wifi了。
回复 支持 反对

使用道具 举报

发表于 2013-12-18 12:25:21 | 显示全部楼层
LZ真牛啊。我看你界面上连风扇都能控制,还有个进度条,显然是用来控制风扇风速的,请问一下控制风扇风速用的是什么方法?继电器只能控制电路开合啊,可风扇不是只能通过按钮或旋钮来控制风力的吗?你是怎么实现的?
回复 支持 反对

使用道具 举报

发表于 2013-12-18 13:48:19 | 显示全部楼层
LZ的2个终端都比较典型,一个继电器插座,这几乎是万能的;一个直接结合具体电器。如果能详细的把各板子的选材、连接、电源的考虑等细节,展示出来,那大家感激不尽,可以让很多人少走弯路了。你这个几乎已经是个半产品了,很实用,跟这里大部分都是个实验不是一个数量级的。
期待LZ详解!
回复 支持 反对

使用道具 举报

发表于 2013-12-18 23:02:23 | 显示全部楼层
怎么把网络信号转换成nrf24l射频信号呢
回复 支持 反对

使用道具 举报

发表于 2013-12-21 18:00:02 | 显示全部楼层
继电器模块也要请教。
这里面装了主控板、2.4g、继电器,还有这个电源怎么弄的?这个AD很大的,不是插座原有的吧?这些怎么装下的?
还有这个USB串口是怎么固定的?似乎没看到PCB的。请LZ赐教啊!
回复 支持 反对

使用道具 举报

发表于 2014-1-19 21:10:18 | 显示全部楼层
楼主真厉害啊
回复 支持 反对

使用道具 举报

发表于 2014-1-25 14:14:58 | 显示全部楼层
不错不错,外观最好在好看点
回复 支持 反对

使用道具 举报

发表于 2014-1-25 21:05:11 | 显示全部楼层
支持一下````````````````
回复 支持 反对

使用道具 举报

发表于 2014-1-28 09:36:57 | 显示全部楼层
期待楼主早日公布详情,造福小白。
回复 支持 反对

使用道具 举报

发表于 2014-2-8 22:12:47 | 显示全部楼层
I留名 漫漫看
回复 支持 反对

使用道具 举报

发表于 2014-2-9 01:15:53 | 显示全部楼层

厉害!!!!!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-20 21:59 , Processed in 0.043556 second(s), 27 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表