When the methoD MicrophoneRecord.Start() is called, the main thread freezez for about a second. This methon cant be executed on another thread. I have no idea on what causes the problem
` InputAction record;
WhisperManager mg;
MicrophoneRecord microphoneRecord;
float time = 0;
readonly float maxTime = 5f;
string text;
public bool recStarted = false;
void Awake()
{
mg = gameObject.AddComponent<WhisperManager>();
microphoneRecord = gameObject.AddComponent<MicrophoneRecord>();
microphoneRecord.OnRecordStop += MicrophoneRecord_OnRecordStop;
record = InputSystem.actions.FindAction("Record");
record.performed += Record_performed;
}
private void Record_performed(InputAction.CallbackContext obj)
{
RecordStart();
}
private void Update()
{
if (record.IsPressed() && time < maxTime)
{
RecordStart();
time += Time.deltaTime;
}
else if ((!record.IsPressed() && recStarted) || (time > maxTime && recStarted))
{
if (time > maxTime) Debug.LogWarning("Out of max recording time!");
microphoneRecord.StopRecord();
}
}
private async void MicrophoneRecord_OnRecordStop(AudioChunk recordedAudio)
{
time = 0f;
var res = await mg.GetTextAsync(recordedAudio.Data, recordedAudio.Frequency, recordedAudio.Channels);
if (res == null)
return;
text = res.Result;
Debug.Log(res.Result + " | " + res.Language);
}
private void RecordStart()
{
if (recStarted) return;
recStarted = true;
mg.language = "en";
microphoneRecord.SelectedMicDevice = Microphone.devices[0];
microphoneRecord.maxLengthSec = (int) maxTime;
microphoneRecord.StartRecord(); //THE PROBLEM IS CAUSED HERE
Debug.Log("started");
}
`
When the methoD MicrophoneRecord.Start() is called, the main thread freezez for about a second. This methon cant be executed on another thread. I have no idea on what causes the problem
` InputAction record;
`