Android 将音频与歌词同步
我正在尝试同步音频文件和歌词文件(字符串格式)。在阅读了许多关于SO的文章之后,我尝试使用语音转换文本从音频中获取文本。但它不听音频,而是等待演讲。歌词文件需要根据歌曲转换为SRT文件。下面的问题怎么可能Android 将音频与歌词同步,android,audio,android-mediaplayer,Android,Audio,Android Mediaplayer,我正在尝试同步音频文件和歌词文件(字符串格式)。在阅读了许多关于SO的文章之后,我尝试使用语音转换文本从音频中获取文本。但它不听音频,而是等待演讲。歌词文件需要根据歌曲转换为SRT文件。下面的问题怎么可能 使用TTS收听音频文件播放?这样做对吗 如何将歌词文件(字符串格式)转换为SRT文件 如有任何建议/指导,将不胜感激。 下面的代码等待我说一些话。但我需要它来听音频文件播放。 到目前为止我已经尝试过的代码: @Override protected void onCreate(Bundle sa
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sr = SpeechRecognizer.createSpeechRecognizer(this);
sr.setRecognitionListener(new listener());
class listener implements RecognitionListener
{
public void onReadyForSpeech(Bundle params)
{
Log.d(TAG, "onReadyForSpeech");
}
public void onBeginningOfSpeech()
{
Log.d(TAG, "onBeginningOfSpeech");
}
public void onRmsChanged(float rmsdB)
{
Log.d(TAG, "onRmsChanged");
}
public void onBufferReceived(byte[] buffer)
{
Log.d(TAG, "onBufferReceived");
}
public void onEndOfSpeech()
{
Log.d(TAG, "onEndofSpeech");
}
public void onError(int error)
{
String mError=null;
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
switch (error) {
case SpeechRecognizer.ERROR_NETWORK_TIMEOUT:
mError = " network timeout";
sr.startListening(intent);
break;
case SpeechRecognizer.ERROR_NETWORK:
mError = " network" ;
//toast("Please check data bundle or network settings");
return;
case SpeechRecognizer.ERROR_AUDIO:
mError = " audio";
break;
case SpeechRecognizer.ERROR_SERVER:
mError = " server";
sr.startListening(intent);
break;
case SpeechRecognizer.ERROR_CLIENT:
mError = " client";
break;
case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:
mError = " speech time out" ;
break;
case SpeechRecognizer.ERROR_NO_MATCH:
mError = " no match" ;
sr.startListening(intent);
break;
case SpeechRecognizer.ERROR_RECOGNIZER_BUSY:
mError = " recogniser busy" ;
break;
case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS:
mError = " insufficient permissions" ;
break;
}
Log.d(TAG, "error " + mError);
}
public void onResults(Bundle results)
{
String str = new String();
Log.d(TAG, "onResults " + results);
ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
for (int i = 0; i < data.size(); i++)
{
Log.d(TAG, "result " + data.get(i));
str += data.get(i);
}
}
public void onPartialResults(Bundle partialResults)
{
Log.d(TAG, "onPartialResults");
}
public void onEvent(int eventType, Bundle params)
{
Log.d(TAG, "onEvent " + eventType);
}
}
public void onSongPicked()
{
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
sr.startListening(intent);}
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
sr=SpeechRecognizer.createSpeechRecognizer(此);
sr.setRecognitionListener(新的listener());
类侦听器实现识别侦听器
{
ReadyForSpeech上的公共void(Bundle参数)
{
Log.d(标签“onReadyForSpeech”);
}
开始时的公共无效fSpeech()
{
Log.d(标签“onbeginingofspeech”);
}
在RMSCHANGED上的公共无效(浮动rmsdB)
{
Log.d(标签“onRmsChanged”);
}
已接收公共无效onBufferReceived(字节[]缓冲区)
{
Log.d(标记“onBufferReceived”);
}
公共无效onEndOfSpeech()
{
Log.d(标签“onEndofSpeech”);
}
公共无效onError(内部错误)
{
字符串mError=null;
意向意向=新意向(识别意向、行动、识别言语);
intent.putExtra(识别器intent.EXTRA_语言_模型,
识别者意图、语言、模型、自由形式);
开关(错误){
案例语音识别器。错误\网络\超时:
mError=“网络超时”;
高级督察(意向);
打破
案例SpeechRecognizer.ERROR\u网络:
mError=“网络”;
//toast(“请检查数据包或网络设置”);
返回;
case SpeechRecognizer.ERROR\u音频:
mError=“音频”;
打破
案例SpeechRecognizer.ERROR\u服务器:
mError=“服务器”;
高级督察(意向);
打破
案例SpeechRecognizer.ERROR\u客户端:
mError=“客户”;
打破
case SpeechRecognizer.ERROR\u SPEECH\u超时:
mError=“语音超时”;
打破
case SpeechRecognizer.ERROR\u NO\u匹配:
mError=“不匹配”;
高级督察(意向);
打破
案例SpeechRecognizer.ERROR\u RECOGNIZER\u BUSY:
mError=“识别器忙”;
打破
案例SpeechRecognizer.ERROR\u权限不足\u:
mError=“权限不足”;
打破
}
Log.d(标记“错误”+mError);
}
公共结果(捆绑结果)
{
String str=新字符串();
Log.d(标签“onResults”+结果);
ArrayList data=results.getStringArrayList(SpeechRecognitor.results\u RECOGNITION);
对于(int i=0;i