对不起SOF的新手,我的问题似乎有点含糊。
使用Android工作室,我想能够上传的音频文件和从音频文件生成一个文本文件,对火力。它们是链接的,但是我只能将音频文件上传到Firebase实时数据库。有什么方法可以将.3gp文件和.txt文件合并并上传?谢谢。
编辑:到目前为止,这是我的代码。这是相当凌乱只是想获得的文件一起。谢谢。
私人的ImageButton recordButton; 私人的TextView txtRec;
private MediaRecorder mRecorder;
private String mTextFileName = null;
private String mFileName = null;
private static final String LOG_TAG = "Record_Log";
private ProgressDialog mProgress;
private StorageReference mStorage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_speech);
checkPermission();
final TextView txtRec = findViewById(R.id.speechOutput);
txtRec.setFocusable(false);
final SpeechRecognizer mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
recordButton = (ImageButton) findViewById(R.id.button);
mStorage = FirebaseStorage.getInstance().getReference();
mProgress = new ProgressDialog(this);
mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
mFileName += "/recorded_audio.3gp";
mTextFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
mTextFileName += "/recorded_text.txt";
final Intent mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,
Locale.getDefault());
mSpeechRecognizer.setRecognitionListener(new RecognitionListener() {
@Override
public void onReadyForSpeech(Bundle bundle) {
}
@Override
public void onBeginningOfSpeech() {
}
@Override
public void onRmsChanged(float v) {
}
@Override
public void onBufferReceived(byte[] bytes) {
}
@Override
public void onEndOfSpeech() {
}
@Override
public void onError(int i) {
}
@Override
public void onResults(Bundle bundle) {
//getting all the matches
ArrayList<String> matches = bundle
.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
//displaying the first match
if (matches != null)
txtRec.setText(matches.get(0));
}
@Override
public void onPartialResults(Bundle bundle) {
}
@Override
public void onEvent(int i, Bundle bundle) {
}
});
recordButton.findViewById(R.id.button).setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
mSpeechRecognizer.stopListening();
txtRec.setHint("You will see input here");
startRecording();
break;
case MotionEvent.ACTION_UP:
mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
txtRec.setText("");
txtRec.setHint("Listening...");
stopRecording();
break;
default:
break;
}
return false;
}
});
}
private void startRecording() {
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.prepare();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}
mRecorder.start();
}
private void stopRecording() {
mRecorder.stop();
mRecorder.release();
mRecorder = null;
uploadAudio();
}
private void uploadAudio() {
mProgress.setMessage("Sending Audio...");
final StorageReference filepath = mStorage.child("Audio").child("new_audio.3gp");
Uri uri = Uri.fromFile(new File(mFileName));
filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
mProgress.dismiss();
txtRec.setText("Sent");
}
});
}