gpt4 book ai didi

android - Delphi XE5 Firemonkey API调用

转载 作者:行者123 更新时间:2023-12-03 00:49:12 34 4
gpt4 key购买 nike

我试图通过直接调用android api TJAudioRecord在firemonkey中录制音频,但是它不起作用,无论我尝试了什么,audioRecord.getState都会返回STATE_UNINITIALIZED,请帮忙吗?

该功能有误

  audioRecord := 

TJAudioRecord.JavaClass.init(TJMediaRecorder_AudioSource.JavaClass.VOICE_COMMUNICATION,
16000,
TJAudioFormat.JavaClass.CHANNEL_IN_MONO,
TJAudioFormat.JavaClass.ENCODING_PCM_16BIT,
bufferSize);

完整的代码
 bufferSize := TJAudioRecord.JavaClass.getMinBufferSize(16000,
TJAudioFormat.JavaClass.CHANNEL_IN_MONO,
TJAudioFormat.JavaClass.ENCODING_PCM_16BIT);

if (bufferSize <> TJAudioRecord.JavaClass.ERROR_BAD_VALUE) then
begin
audioRecord := TJAudioRecord.JavaClass.init(TJMediaRecorder_AudioSource.JavaClass.VOICE_COMMUNICATION,
16000,
TJAudioFormat.JavaClass.CHANNEL_IN_MONO,
TJAudioFormat.JavaClass.ENCODING_PCM_16BIT,
bufferSize);
ShowMessage(IntToStr(buffersize));
if (audioRecord.getState = TJAudioRecord.JavaClass.STATE_INITIALIZED)then begin
//then begin
audioRecord.startRecording;
ShowMessage('ok');
end;
end;
except
ShowMessage('Error 0');
end;

最佳答案

我使用以下代码,并且它可以在我的Samsung Galaxy Note III上运行。

  Ses := TJAudioRecord.JavaClass.init(TJMediaRecorder_AudioSource.JavaClass.MIC, 11025, TJAudioFormat.JavaClass.CHANNEL_IN_MONO, TJAudioFormat.JavaClass.ENCODING_PCM_16BIT, 44100 * 2);
(Ses As JAudioRecord).startRecording;
Okunan := 0;
M := TMemoryStream.Create;
for I := 1 to 2 do
Begin
Tampon := TJavaArray<SmallInt>.Create(44100);
Okunan := Okunan + (Ses As JAudioRecord).read(Tampon, 0, 44100);
M.Write(Tampon.Data^, Tampon.Length * 2);
Tampon.Free;
End;
(Ses As JAudioRecord).stop;
Ses.release;
M.SaveToFile(TPath.GetRingtonesPath+'/ses.raw');

关于android - Delphi XE5 Firemonkey API调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23087084/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com