Skip to content

Instantly share code, notes, and snippets.

@Shinpeim
Created September 29, 2012 09:42
Show Gist options
  • Save Shinpeim/3803586 to your computer and use it in GitHub Desktop.
Save Shinpeim/3803586 to your computer and use it in GitHub Desktop.
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment