Skip to content

Instantly share code, notes, and snippets.

@Shinpeim
Created September 29, 2012 09:42
Show Gist options
  • Select an option

  • Save Shinpeim/3803586 to your computer and use it in GitHub Desktop.

Select an option

Save Shinpeim/3803586 to your computer and use it in GitHub Desktop.

Revisions

  1. Shinpeim created this gist Sep 29, 2012.
    32 changes: 32 additions & 0 deletions add_header.pl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    use strict;
    use warnings;
    use IO::File;

    my $filename = shift or die "usage: $0 source > dest";

    my $fp = IO::File->new($filename,"r");
    my $pcm = "";
    while ($fp->read(my $buff,1024)) {
    $pcm .= $buff;
    }
    $fp->close;


    my $size = length $pcm;
    my @wave_header = (
    "RIFF",
    pack("V",$size + 36), #全体のファイルサイズ - 8
    "WAVE",
    "fmt ",
    "\x10\x00\x00\x00", #リニアPCM
    "\x01\x00", #リニアPCM
    "\x01\x00", #モノラル
    "\x40\x1f\x00\x00", #8kHz
    "\x40\x1f\x00\x00", #データ速度
    "\x01\x00", #ブロックサイズ
    "\x08\x00", #量子化ビットサイズ
    "data",
    pack("V",$size),
    );

    print join("",@wave_header,$pcm);