public void InvokeAuthorize()
{
AuthorizeOption option = new AuthorizeOption();
option.scope = "scope.record"; // 假设您想要请求用户信息
option.success = (result) => { Debug.Log("权限调用成功 "+result.errMsg); };
option.fail = (result) => { Debug.Log("权限调用失败 " + result.errMsg); };
WX.Authorize(option);
}
public void StartRecord()
{
GetSettingOption getSettingOption = new GetSettingOption();
getSettingOption.success = (result) => { };
WX.GetSetting(new GetSettingOption());
RecorderManagerStartOption option = new RecorderManagerStartOption();
m_VoiceBottonText.text = "正在录音中...";
option.sampleRate = 8000;
option.format = "wav";
option.numberOfChannels = 2;
// 无论成功还是失败都会执行
// 处理授权成功的逻辑
wxRecorder.Start(option);
Debug.Log("开始录音1");
wxRecorder.OnStart(() =>
{
Debug.Log("开始录音2");
});
}
/// <summary>
/// 结束录制
/// </summary>
void Success(WXReadFileResponse result)
{
Debug.Log("录音读取完成! ");
Debug.Log(result.binData.ToString());
//AudioClip audioClip1 = ;
if(!string.IsNullOrEmpty(result.binData.ToString()))
{
AcceptData(result.binData);
}
}
private bool IsreadStop;
public void StopRecord()
{
IsreadStop = true;
ReadFileParam readFile = new ReadFileParam();
m_VoiceBottonText.text = "按住按钮,开始录音";
m_RecordTips.text = "录音结束,正在识别...";
wxRecorder.Stop();
Debug.Log("结束录音功能");
wxRecorder.OnStop(res =>
{
if (IsreadStop)
{
Debug.Log(res.tempFilePath);
readFile.filePath = res.tempFilePath;
WXBase.GetFileSystemManager().ReadFile(readFile);
readFile.success = Success;
IsreadStop = false;
}
});
//m_VoiceInputs.StopRecordAudio(AcceptClip);
}
