2012-04-07 15 views
5

en mi aplicación estoy grabando el habla para que tenga que configurar mi emulador capaz de grabar voz. he buscado en el google tengo alguna solución que es necesario para iniciar el emulador de forma manual con la opción de medios. utilizo el siguiente cmd pero obtuve el error.¿Cómo habilito la opción de medios en el emulador de Android con la línea de comandos

emulator -avd Test -audio-in MIC 

uso Android 2.2 (Api 2.2) en Windows 7. ¿Cómo habilito la opción MIC en mi emulador? por favor, ayúdame.

me dieron el siguiente error:

>emulator -avd Test -audio-in MIC 

>unknown option: -audio-in 

please use -help for a list of valid options

Respuesta

9

intenta utilizar este ejemplo:

package com.benmccann.android.hello; 

import java.io.File; 
import java.io.IOException; 

import android.media.MediaRecorder; 
import android.os.Environment; 

/** 
* @author <a href="http://www.benmccann.com">Ben McCann</a> 
*/ 

public class AudioRecorder { 

final MediaRecorder recorder = new MediaRecorder(); 
final String path; 

/** 
* Creates a new audio recording at the given path (relative to root of SD card). 
*/ 
public AudioRecorder(String path) { 
this.path = sanitizePath(path); 
} 

private String sanitizePath(String path) { 
    if (!path.startsWith("/")) { 
    path = "/" + path; 
} 
if (!path.contains(".")) { 
    path += ".3gp"; 
} 
return Environment.getExternalStorageDirectory().getAbsolutePath() + path; 
} 

/** 
* Starts a new recording. 
*/ 
public void start() throws IOException { 
    String state = android.os.Environment.getExternalStorageState(); 
    if(!state.equals(android.os.Environment.MEDIA_MOUNTED)) { 
    throw new IOException("SD Card is not mounted. It is " + state + "."); 
} 

// make sure the directory we plan to store the recording in exists 
File directory = new File(path).getParentFile(); 
    if (!directory.exists() && !directory.mkdirs()) { 
    throw new IOException("Path to file could not be created."); 
} 

recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
recorder.setOutputFile(path); 
recorder.prepare(); 
recorder.start(); 
} 

/** 
* Stops a recording that has been previously started. 
*/ 
public void stop() throws IOException { 
recorder.stop(); 
recorder.release(); 
} 

} 

Esperanza ayuda esto. Háganos saber cómo va, o si necesita ayuda adicional.

+0

gracias por la codificación tengo un conjunto exacto de codificación. mi consulta está configurada emulador capaz de grabar voz. emulator -avd Test -audio-in MIC da error. ¿Es posible en el emulador habilitar MIC? –

+0

en el emulador no puedo obtener la grabación de audio –

Cuestiones relacionadas