⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rawwriter.java

📁 It is the Speech recognition software. It is platform independent. To execute the source code,
💻 JAVA
字号:
/* * Copyright 1999-2004 Carnegie Mellon University.   * Portions Copyright 2002-2004 Sun Microsystems, Inc.   * Portions Copyright 2002-2004 Mitsubishi Electric Research Laboratories. * All Rights Reserved.  Use is subject to license terms. *  * See the file "license.terms" for information on usage and * redistribution of this file, and for a DISCLAIMER OF ALL  * WARRANTIES. * */package edu.cmu.sphinx.tools.audio;import java.io.IOException;import java.io.OutputStream;import javax.sound.sampled.AudioFormat;/** * Writes raw audio to a file, handling sample size, endian format, * and signed/unsigned data. */public class RawWriter {    private OutputStream outputStream;    private int bytesPerSample;    private boolean signedData;    private boolean bigEndian;    /**     */    public RawWriter(OutputStream outputStream,                     AudioFormat audioFormat) {        AudioFormat.Encoding encoding = audioFormat.getEncoding();                this.outputStream = outputStream;        this.bytesPerSample = audioFormat.getSampleSizeInBits() / 8;        if (encoding == AudioFormat.Encoding.PCM_SIGNED) {            this.signedData = true;        } else if (encoding == AudioFormat.Encoding.PCM_UNSIGNED) {            this.signedData = false;        } else {            System.err.println("Unsupported audio encoding: " + encoding);            System.exit(-1);        }        this.bigEndian = audioFormat.isBigEndian();    }    /**     * Writes the sample to the output stream.     *     * @throws java.io.IOException     */    public void writeSample(int sample) throws IOException {        /* First byte contains the big endian byte that carries the sign.         */        if (signedData) {            outputStream.write(sample >> ((bytesPerSample - 1) * 8));         } else {            outputStream.write((sample >> ((bytesPerSample - 1) * 8)) & 0xff);        }        /* Now just output the rest of the data in big endian form.         */        for (int i = bytesPerSample - 2; i >= 0; i--) {            outputStream.write((sample >> (i * 8)) & 0xff);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -