Git Product home page Git Product logo

androidspeechrecognizer's Introduction

AndroidSpeechRecognizer 2019.03.28 Android Pie 기준

Button을 눌렀을 때, 음성인식 구현

Menifests 퍼미션 추가

  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.RECORD_AUDIO"/>
  • 안드로이드 내부 기기의 마이크를 이용해 음성인식을 구현하기 위해서는 위의 권한이 필요합니다.
    • <주의> Android 마시멜로 버전부터 퍼미션만 추가하면 권한이 허용되지 않아 사용자의 권한 동의가 필요합니다

SpeechRecognizer

   SpeechRecognizer mRecognizer;
 
 // 생략
 
   Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
   i.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getPackageName());
   i.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "ko-KR");

 
   mRecognizer = SpeechRecognizer.createSpeechRecognizer(MainActivity.this);
   
   mRecognizer.setRecognitionListener(listener);
   
  // 생략
   mRecognizer.startListening(i);  //음성인식 기능을 키는 함수이므로 onClick같은 함수에서 호출하기 바람

SpeechRecognizer Listener

  RecognitionListener listener = new RecognitionListener() {

          @Override
          public void onReadyForSpeech(Bundle params) {

          }

          @Override
          public void onBeginningOfSpeech() {

          }

          @Override
          public void onRmsChanged(float rmsdB) {
              Log.d("sound",""+rmsdB);
              
              //입력되는 데시벨 크기를 상수로 
          }

          @Override
          public void onBufferReceived(byte[] buffer) {

          }

          @Override
          public void onEndOfSpeech() {

          }

          @Override
          public void onError(int error) {

          }

          @Override
          public void onResults(Bundle results) {
              String key = "";
              key = SpeechRecognizer.RESULTS_RECOGNITION;
              ArrayList<String> mResult = results.getStringArrayList(key);
              String[] rs = new String[mResult.size()];
              mResult.toArray(rs);
              ((TextView)(findViewById(R.id.text))).setText("" + rs[index]);
          }

          @Override
          public void onPartialResults(Bundle partialResults) {

          }

          @Override
          public void onEvent(int eventType, Bundle params) {

          }
      };

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.