M
morgan520
Unregistered / Unconfirmed
GUEST, unregistred user!
[blue][/blue]
如下代码是我的一个录音的以单元。
---------------------------------------------------------------------------
{
录音控制
}
unit recordUtil;
interface
uses Classes, protocolOjbect, sysUtils;
type
TRecordHelper = class(TObject)
private
{ Private declarations }
memory: TMemoryStream;
currentFileName: string;
bOnWork: boolean;
public
constructor Create;
function startRecord(fileDir: string;
fileName: string): boolean;
overload;
function recordBuffer(data: Pointer;
size: Integer): boolean;
function stopRecord: boolean;
end;
implementation
uses commonUtil;
constructor TRecordHelper.Create;
begin
inherited;
bOnWork := false;
end;
{ TRecordHelper }
function TRecordHelper.recordBuffer(data: Pointer;
size: Integer): boolean;
begin
if bOnWork then
memory.WriteBuffer(data, size);
end;
function TRecordHelper.startRecord(fileDir: string;
fileName: string): boolean;
begin
if (DirectoryExists(fileDir) = false) then
if (CreateDir(fileDir) = false) then
begin
result := false;
exit;
end;
currentFileName := format('%s/%s.wav', [fileDir, fileName]);
CreateWav(1, { 1(单声)或者2(立体声) }
8, { 8或者16,代表8位或16位声音 }
8000, { 声音频率,如11025,22050, 44100}
currentFileName);
memory := TmemoryStream.create;
memory.LoadFromFile(currentFileName);
memory.Seek(sizeof(TWavHeader), 0);
bOnWork := true;
end;
function TRecordHelper.stopRecord: boolean;
begin
if bOnWork then
begin
bOnWork := false;
memory.SaveToFile(currentFileName);
end;
memory.free;
memory := nil;
end;
end.
---------------------------------------------------------
我运用本录音类的方法如下:
首先调用startRecord;
然后在有话音包过来的时候使用recordBuffer;
在结束通话的时候用stopRecord保存为WAV文件。
---------------------------------------------------------
问题是:
我得到WAV文件用REALPLAYER播放的时候,才开始播放就接受了(几百K的文件)。说明保存话音的方法有问题,希望各位大哥,给点建议!谢谢!
如下代码是我的一个录音的以单元。
---------------------------------------------------------------------------
{
录音控制
}
unit recordUtil;
interface
uses Classes, protocolOjbect, sysUtils;
type
TRecordHelper = class(TObject)
private
{ Private declarations }
memory: TMemoryStream;
currentFileName: string;
bOnWork: boolean;
public
constructor Create;
function startRecord(fileDir: string;
fileName: string): boolean;
overload;
function recordBuffer(data: Pointer;
size: Integer): boolean;
function stopRecord: boolean;
end;
implementation
uses commonUtil;
constructor TRecordHelper.Create;
begin
inherited;
bOnWork := false;
end;
{ TRecordHelper }
function TRecordHelper.recordBuffer(data: Pointer;
size: Integer): boolean;
begin
if bOnWork then
memory.WriteBuffer(data, size);
end;
function TRecordHelper.startRecord(fileDir: string;
fileName: string): boolean;
begin
if (DirectoryExists(fileDir) = false) then
if (CreateDir(fileDir) = false) then
begin
result := false;
exit;
end;
currentFileName := format('%s/%s.wav', [fileDir, fileName]);
CreateWav(1, { 1(单声)或者2(立体声) }
8, { 8或者16,代表8位或16位声音 }
8000, { 声音频率,如11025,22050, 44100}
currentFileName);
memory := TmemoryStream.create;
memory.LoadFromFile(currentFileName);
memory.Seek(sizeof(TWavHeader), 0);
bOnWork := true;
end;
function TRecordHelper.stopRecord: boolean;
begin
if bOnWork then
begin
bOnWork := false;
memory.SaveToFile(currentFileName);
end;
memory.free;
memory := nil;
end;
end.
---------------------------------------------------------
我运用本录音类的方法如下:
首先调用startRecord;
然后在有话音包过来的时候使用recordBuffer;
在结束通话的时候用stopRecord保存为WAV文件。
---------------------------------------------------------
问题是:
我得到WAV文件用REALPLAYER播放的时候,才开始播放就接受了(几百K的文件)。说明保存话音的方法有问题,希望各位大哥,给点建议!谢谢!