记录/保存的语音识别意图音频 [英] record/save audio from voice recognition intent
问题描述
在问这个问题,我检查了所有计算器与此相关的问题,其他线程没有成功,所以,请不要链接到其他线程的回答,:)
Before asking this question, I checked all stackoverflow other threads related to this issue without any success, so please, don't answer with links to other threads, :)
我想保存/记录,谷歌用于语音到文本操作(使用RecognizerIntent或SpeechRecognizer)识别服务的音频
I want to save/record the audio that google recognition service used for speech to text operation (using RecognizerIntent or SpeechRecognizer).
我经历了很多的想法:
- 从RecognitionListener onBufferReceived:我知道,这是行不通的,只是测试一下,看看发生了什么,onBufferReceived不会被调用 (符合JB 4.3测试了Galaxy Nexus的)
- 在使用的媒体记录器:不工作。它打破语音识别。只允许话筒一个操作
- 在试图寻找其中,识别服务是节约的讲话执行前临时音频文件为文本的API来复制它,但都没有成功
- onBufferReceived from RecognitionListener: I know, this is not working, just test it to see what happens and onBufferReceived is never called (tested on galaxy nexus with JB 4.3)
- used a media recorder: not working. it's breaking speech recognition. only one operation is allowed for mic
- tried to find where recognition service is saving the temporary audio file before the execution of the speech to text api to copy it, but without success
我几乎绝望了,但我只注意到谷歌保持应用程序在做什么,我需要做的!!!!我debuged了一点保持应用程序中使用的logcat和应用程序也被调用RecognizerIntent.ACTION_RECOGNIZE_SPEECH(就像我们,开发商做)来触发语音到文本。但是,如何让被保存音频?可以说,它是一个隐藏的API?是谷歌欺骗:)?
I was almost desperate but I just noticed that google keep application is doing what I need to do!!!! I debuged a little the keep application using logcat and the app is also calling the "RecognizerIntent.ACTION_RECOGNIZE_SPEECH" (like we, developers, do) to trigger speech to text. but, how keep is saving the audio? can it be a hide api? is google "cheating" :) ?
感谢您的帮助
最好的问候
推荐答案
@ Kaarel的回答几乎是完整的 - 所产生的声音是在 intent.getData()
键,可读取使用 ContentResolver的
@Kaarel's answer is almost complete - the resulting audio is in intent.getData()
and can be read using ContentResolver
不幸的是,返回的AMR文件是低质量 - 我没能找到一种方式来获得高品质录音。我想除了音频/ AMR以外的任何值返回的空intent.getData()
。
Unfortunately, the AMR file that is returned is low quality - I wasn't able to find a way to get high quality recording. Any value I tried other than "audio/AMR" returned null in intent.getData()
.
如果你找到一种方式来获得高品质录音 - !请评论或添加答案
If you find a way to get high quality recording - please comment or add an answer!
public void startSpeechRecognition() {
// Fire an intent to start the speech recognition activity.
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
// secret parameters that when added provide audio url in the result
intent.putExtra("android.speech.extra.GET_AUDIO_FORMAT", "audio/AMR");
intent.putExtra("android.speech.extra.GET_AUDIO", true);
startActivityForResult(intent, "<some code you choose>");
}
// handle result of speech recognition
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// the resulting text is in the getExtras:
Bundle bundle = data.getExtras();
ArrayList<String> matches = bundle.getStringArrayList(RecognizerIntent.EXTRA_RESULTS)
// the recording url is in getData:
Uri audioUri = data.getData();
ContentResolver contentResolver = getContentResolver();
InputStream filestream = contentResolver.openInputStream(audioUri);
// TODO: read audio file from inputstream
}
这篇关于记录/保存的语音识别意图音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!