【问题标题】:How to use wit.ai with ogg files如何将 wit.ai 与 ogg 文件一起使用
【发布时间】:2017-08-15 05:23:27
【问题描述】:

我正在尝试将 wit.ai 语音转换为文本,这样我就可以将录制的音频从 whatsapp 转换为文本,问题是我不断出错。

wit.ai 支持 Content-Type 标头的“audio/wav”、“audio/mpeg3”、“audio/ulaw”和“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();

我做错了什么?

【问题讨论】:

    标签: android audio speech-to-text wit.ai


    【解决方案1】:

    使用libvorbis-libogg-android 将ogg 转换为PCM 并发送audio/raw 请求。

    【讨论】:

    • 你能帮忙看看这个库吗?如何使用它将 ogg 转换为 pin?
    猜你喜欢
    • 2018-07-05
    • 1970-01-01
    • 2019-04-16
    • 1970-01-01
    • 2011-09-24
    • 1970-01-01
    • 2013-04-05
    • 2012-05-20
    • 2015-01-24
    相关资源
    最近更新 更多