【问题标题】:java.lang.OutOfMemoryError Android - big arrayjava.lang.OutOfMemoryError Android - 大数组
【发布时间】:2016-03-09 13:44:53
【问题描述】:

我是 Android 开发新手,请帮助我解决我的错误。

我正在读取一个 wav 文件并进行处理以与另一个 wav 文件进行比较。我得到 OutOfMemoryError 并假设它可能是由于大数组。 这是我的 processing() 方法:

public void processing2(){
    System.out.println("reading in the file  .... ");
    float[] arr1 = readWav1("sink1.wav");
    float[] arr2 = readWav1("think1.wav");
    System.out.println("arr1 size: "+arr1.length);
    System.out.println("arr2 size: "+arr2.length);

    System.out.println("preprocessing .... ");
    FeatureVector a = extractFeatureFromExtractedAmplitureByteArray(arr1);
    FeatureVector b = extractFeatureFromExtractedAmplitureByteArray(arr2);

    System.out.println("vector a num of frames: " + a.getNoOfFrames());
    System.out.println("vector b num of frames: "+b.getNoOfFrames());

    //converting to 1d array
    flattened1 = twoDimToOne(a.getFeatureVector());
    flattened2 = twoDimToOne(b.getFeatureVector());

    System.out.println("1d array1 size: "+flattened1.length);
    System.out.println("1d array2 size: "+flattened2.length);

    System.out.println("DTW .... ");
    d = new DTW(flattened1, flattened2);
    System.out.println(d);
}

这是logcat:

System.out: reading in the file  .... 
System.out: File reading in progress..
System.out: File reading in progress..
System.out: arr1 size: 73750
System.out: arr2 size: 65558
System.out: preprocessing .... 
System.out: noOfFrames       110  samplePerFrame     512  EPD length   28556
System.out: noOfFrames       100  samplePerFrame     512  EPD length   25872
System.out: vector a num of frames: 110
System.out: vector b num of frames: 100
System.out: 1d array1 size: 4290
System.out: 1d array2 size: 3900
System.out: DTW .... 
dalvikvm-heap: Clamp target GC heap from 131.007MB to 128.000MB
dalvikvm-heap: Clamp target GC heap from 134.938MB to 128.000MB
dalvikvm-heap: Forcing collection of SoftReferences for 31216-byte allocation
dalvikvm-heap: Clamp target GC heap from 134.938MB to 128.000MB
dalvikvm-heap: Out of memory on a 31216-byte allocation.
…
AndroidRuntime: FATAL EXCEPTION: main
java.lang.OutOfMemoryError
at java.lang.reflect.Array.createMultiArray(Native Method)

谢谢。

【问题讨论】:

  • 以下是避免 OOM 问题的一种方法。但是,如果您使用像 512 这样的低内存,那么在没有大数组的情况下比较 wav 文件的更好方法也不会更好。
  • 我在清单中添加了 android:largeHeap="true",但没有用。手动增加堆大小,也不起作用。我存储到数组中,因为我需要频率。我需要检测这个人对这个词的发音程度。您能提出任何解决方案吗?
  • 您可以搜索比较 wav 文件。您不需要逐个字节地对它们进行比较。
  • 我认为你需要一些开源语音检测。
  • 你从哪里获取这个 wav 文件,从服务器,从 sdcard?如果来自 sdcard 那么你不需要获取 wav 文件你可以有文件的路径并相应地处理它。

标签: android arrays memory-management out-of-memory


【解决方案1】:

在您的 manifest.xml 应用程序标签中添加 android:largeHeap="true"

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"/>

【讨论】:

猜你喜欢
  • 2016-11-12
  • 2015-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-06
  • 2013-11-05
  • 2010-12-29
相关资源
最近更新 更多