音声ファイルの分割


言葉を学習するときなど、会話など区切って再生したい場合があります。続けて言われると考える時間がないですからね。会話ごと区切って再生できると便利です。

そこで音声ファイル(WAVフォーマット)を分割するプログラム SoundEdit です。

音声データを、閾値と音声とポーズの持続時間で区切っています。ここでポーズは、閾値以下の値が一定持続時間以上継続するものと定義します。音声は、指定された時間以上続くものと定義します。

Java で、音声ファイルを読み込み・再生する方法については、Java で WAV ファイルを読む のページをご覧ください。

区切りのアルゴリズムは、以下の通りです。

    public void split(int threshold, int interval, int duration) {
        int k = 0;
        int start = 0, end = 0;
        do {
            // loops above threshold values appear
            while (Math.abs(buf[k]) < threshold && ++k < length)
                ;

            // if the above threshold value is found
            if (k < length) {
                start = k;
                end = k;

                // loops until it founds out below
                // threshold period longer than duration value
                while ((Math.abs(buf[k]) > threshold || k - end < duration) && ++k < length) {
                    if (Math.abs(buf[k]) > threshold)
                        end = k;
                }

                // if the above threshold period is longer than interval value
                // and below threshold period is longer than duration value
                if (end - start > interval && (k - end >= duration || k >= length)) {
                    add(new Segment(start, end));
                }
            }
        } while (++k < length);
    }



File(s)Description
SoundEdit 音声ファイルの分割
inserted by FC2 system