gpt4 book ai didi

java - 我可以从语音识别中获取语音数据(例如 mp3 格式)吗?

转载 作者:太空狗 更新时间:2023-10-29 13:33:20 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Android: Voice Recording and saving audio

我是说;

我在 android 上使用语音识别类,并且我成功地进行了语音识别。但我想要真正的语音数据而不是文字。例如,我说 'teacher' 并且 android 让你说老师。哦,好的,但我想要我的声音,其中包括 'teacher'。它在哪里?我可以把它保存到另一个位置吗?

我用这个类来语音转文本:

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;
}

}
}
}

谢谢。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com