2017-08-15 30 views
0

我想用wit.ai語音文本,所以我將能夠將錄製的音頻從whatsapp轉換爲文本,問題是我不斷收到錯誤。如何使用wit.ai與ogg文件

wit.ai支持Content-Type標題的'audio/wav','audio/mpeg3','audio/ulaw'和'audio/raw'。如果使用audio/raw,你還必須提供這些參數:編碼,位數,速率和尾數

我從whatsapp得到的文件是.ogg。

既然不支持這種文件我試過音頻/原與所有可能的變化,但我不斷收到同樣的錯誤:

{ 
    "error" : "Bad request", 
    "code" : "bad-request" 
} 

當我嘗試不同的類型(音頻/ WAV格式例如)我得到一個不同的錯誤這是有道理的:

{ 
    "error" : "Mismatch between the provided content-type and the bytes you sent.\nAre you sure it's a valid sound file?", 
    "code" : "content-type-mismatch" 
} 

爲了得到我做的文件:

Intent intent = getIntent(); 
String action = intent.getAction(); 
String type = intent.getType(); 

Log.w("myapp", "got the intent"); 
if (Intent.ACTION_SEND.equals(action) && type != null) { 
    audioUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); 

對於閱讀我在做文件:

InputStream inputStream = getContentResolver().openInputStream(uri); 
    String type = getContentResolver().getType(uri); 

    Log.w("myapp", "type of file: " + type); 


    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    InputStream fis = getContentResolver().openInputStream(uri); 
    try { 
     byte[] buf = new byte[1024]; 
     int n; 
     while (-1 != (n = fis.read(buf))) 
      baos.write(buf, 0, n); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    Log.w("myapp", Integer.toString(baos.toByteArray().length)); 

    return baos.toByteArray(); 

我在做什麼錯?

回答

0

將ogg轉換爲PCM,併發送libvorbis-libogg-android併發送audio/raw請求。

+0

你能幫助這個圖書館嗎?我如何使用它將ogg轉換爲pin? –