2016-05-14 49 views
1

我正在嘗試創建一個應用程序,該程序允許用戶將Google語音創建的音頻文件上傳到服務器。我已經設法獲取音頻文件的URI,但是如何訪問它或將其轉換爲可監聽的格式?我試圖播放它,但沒有到目前爲止。這是我的。Android將語音保存爲文本音頻

我的演講到文本

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    switch (requestCode){ 
     case REQ_CODE_SPEECH_INPUT: { 
      Bundle bundle = data.getExtras(); 
      if(resultCode==RESULT_OK && null!= data){ 
       ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); 
       vtt.setText(result.get(0)); 
       Uri audioUri = data.getData(); 
       uri.setText(String.valueOf(audioUri)); 
       audioPath = uri.getText().toString(); 

      } 
      break; 

     } 
    } 
} 

當我試圖打audioPath變量。沒有出現。如何將其轉換爲可收聽的格式?

URI的例子,我得到了

content://com.google.android.googlequicksearchbox.AudioProvider/NoteToSelfOriginalAudio1.amr 

謝謝您的幫助

我發現的地方,我應該使用內容解析器和做一些與InputStream的,但林不知道。

+1

的[記錄/保存的語音識別意圖音頻]可能的複製(http://stackoverflow.com/questions/23047433/record-保存音頻從 - 語音識別意圖) –

回答

0

我設法解決了這個問題。

最簡單的方法是使用功能,從Apache的百科全書IO

audioPath = uri.getText().toString(); 
       finalPath = combinedPath.replaceAll(" ",""); 
       Log.d("Filepath",combinedPath.replaceAll(" ","")); 
       ContentResolver contentResolver = getContentResolver(); 
       try{ 
        InputStream filestream = contentResolver.openInputStream(audioUri); 
        File targetFIle = new File(finalPath); 
        FileUtils.copyInputStreamToFile(filestream,targetFIle); 
       }catch (IOException e){ 
        e.toString(); 
       } 
相關問題