3

Possible Duplicate:
Android: Voice Recording and saving audio

I mean ;

I use voice recognition classes on android and I succeed voice recognition. But I want to real voice data not words instead of it. For example I said 'teacher' and android get you said teacher.Oh ok its good but I want to my voice which include 'teacher'.Where is it ? Can I take it and save another location?

I use this class to speech to text :

package net.viralpatel.android.speechtotextdemo;

import java.util.ArrayList;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

    protected static final int RESULT_SPEECH = 1;

    private ImageButton btnSpeak;
    private TextView txtText;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        txtText = (TextView) findViewById(R.id.txtText);

        btnSpeak = (ImageButton) findViewById(R.id.btnSpeak);

        btnSpeak.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                Intent intent = new Intent(
                        RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

                intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");

                try {
                    startActivityForResult(intent, RESULT_SPEECH);
                    txtText.setText("");
                } catch (ActivityNotFoundException a) {
                    Toast t = Toast.makeText(getApplicationContext(),
                            "Ops! Your device doesn't support Speech to Text",
                            Toast.LENGTH_SHORT);
                    t.show();
                }
            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        switch (requestCode) {
        case RESULT_SPEECH: {
            if (resultCode == RESULT_OK && null != data) {

                ArrayList<String> text = data
                        .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

                txtText.setText(text.get(0));
            }
            break;
        }

        }
    }
}

Thanks.

Community
  • 1
  • 1
CompEng
  • 7,161
  • 16
  • 68
  • 122
  • See: http://stackoverflow.com/a/10918416/12547 – Kaarel Nov 04 '12 at 17:44
  • I want to use speech gatherer class I dont want to use mediaplayer class and recording . I want to use google api – CompEng Nov 04 '12 at 18:54
  • If http://stackoverflow.com/a/10918416/12547 does not help you then please be more specific (i.e. improve your question) as to what API you want to use? What is a "speech gatherer class"? – Kaarel Nov 04 '12 at 20:04
  • i updated my question. dont down vote immediately – CompEng Nov 04 '12 at 20:15

1 Answers1

2

So you want to use the Android speech recognition API to obtain both the transcription and the audio of what the user said. The only solution that I know of is to use the SpeechRecognizer-class. This allows you to interact with the speech recognizer(s) installed on the system but you have to implement the UI (microphone button, error message display, etc.) yourself. So it's a little more work than using the plain RecognizerIntent.ACTION_RECOGNIZE_SPEECH. The relevant classes/methods in your case are:

Note that the documentation of the last method includes There is no guarantee that this method will be called, so the speech recognition API is not really designed to allow for audio capture. It also says The sample rate is implementation dependent., i.e. you won't even know how to play back the audio (or save it to wav).

See also the answer https://stackoverflow.com/a/10918416/12547

To summarize:

  • the Android speech recognition API does not return an MP3
  • the Android speech recognition API does not write anything onto the SD card
  • the Android speech recognition API contains a method that returns the audio in a byte array, but you cannot rely on every speech recognition app to implement this method
Community
  • 1
  • 1
Kaarel
  • 10,554
  • 4
  • 56
  • 78
  • I really dont understand. How can i save the file to the sd card. And which file? where is the voice file which include my voice? – CompEng Nov 05 '12 at 17:40
  • 1
    you get a _byte array_, from there on it's up to you what you do with it (e.g. interpret it as 16kHz 16-bit bigendian audio, convert it into MP3, save it onto the SD card) – Kaarel Nov 05 '12 at 17:44
  • 1
    you dont understand me . I want use that class.I dont use mediaplayer record function. I use that class and when I use it and I get text what ı say, but i want to get voice data like mp3 or anotherelse – CompEng Nov 05 '12 at 18:50
  • 2
    I think I _do_ understand you, e.g. I never even mentioned MediaPlayer (I'm not sure why you keep bringing it up). Anyway, I've made one last attempt to make my answer more clear. Note also that this question is already closed because it was an exact duplicate (at least given its formulation). It's always possible that you intended to ask something else, in this case try opening a new question. – Kaarel Nov 05 '12 at 23:03