int CHUNKED_SIZE = 8000; public void recognizeText(byte[] data) throws InterruptedException, IOException { init(); byte[] buffer = new byte[CHUNKED_SIZE]; ByteArrayInputStream stream = new ByteArrayInputStream(data); while (stream.read(buffer) != -1) { send(buffer); } send("EOS"); } String fileName = "F:\aaa.wav"; RandomAccessFile raf = new RandomAccessFile(fileName,"r"); raf.skipBytes(44); byte [] audioData = new byte[(int)(raf.length() - 44)]; raf.readFully(audioData); recognizeText(audioData);
每次读取8000字节