開発環境 メモ帳
実行環境 Windows 7 Home Premium (32bit)

sndrec.cs
using System;
using System.Runtime.InteropServices;
using System.Text;
 
static class Program
{
	[DllImport("winmm.dll")]
	private extern static uint mciSendString(
		string lpszCommand, StringBuilder lpszReturnString, uint cchReturn, IntPtr hwndCallback);
 
	static void Main(string[] args)
	{
		string set1 = "channels 1 samplespersec 8000 bytespersec 8000 alignment 1 bitspersample 8";
		mciSendString("open new type waveaudio alias Rec", null, 0, IntPtr.Zero);
		mciSendString("set Rec " + set1, null, 0, IntPtr.Zero);
		mciSendString("record Rec", null, 0, IntPtr.Zero);
 
		Console.WriteLine("Hit any key.");
		Console.ReadKey();
 
		string fileName = @"sample.wav";
		mciSendString("stop Rec", null, 0, IntPtr.Zero);
		mciSendString("save Rec " + fileName, null, 0, IntPtr.Zero);
		mciSendString("close Rec", null, 0, IntPtr.Zero);
	}
}
 
最終更新:2014年09月25日 09:12