Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot retrieving audio data when using AEC function #290

Open
jackyetz opened this issue May 11, 2024 · 3 comments
Open

cannot retrieving audio data when using AEC function #290

jackyetz opened this issue May 11, 2024 · 3 comments

Comments

@jackyetz
Copy link

jackyetz commented May 11, 2024

Following the "https://placeholder-software.co.uk/dissonance/docs/Tutorials/Acoustic-Echo-Cancellation.html", I am trying to deal with the Echo issue using the class AECHelper (see https://github.com/jackyetz/pub/blob/main/AECHelper.cs).
The following first paragraph of code in my main thread calls AECHelper, and "aechelper.Update()" in the Update() of the main thread. When retrieving the audio data using the following second paragraph of code, I got error prompt (see the bottom paragraph) which happened with "recordClip.GetData".

BTW, if instead using "audioLocal.clip = Microphone.Start(device, true, loopLength, sampleRate)" to retrieve audio data, no error prompt come out.

aechelper = gameObject.AddComponent<AECHelper.AECHelper>();
aechelper.gameobjname = "xiaoyang";  // unity object with an audiosource
aechelper.playlocalspeech = true;       
aechelper.Start();	// start 
while (aechelper.audioclip == null || aechelper.audioclip.length <= 0)
{
    // AudioClip没有内容
    Thread.Sleep(100);
}
audioLocal = aechelper.audiosrc;
int length = recordClip.channels * recordClip.samples;
int isplit = length / recordClip.frequency * 10; //split audio data into ten parts and retrieve one by one。
int micPosition = 0;
float[] micDataTemp;
int i;
while (true)
{
    for (i = 1; i <= isplit - 1; i++) 
    {
        yield return new WaitUntil(() => { micPosition = Microphone.GetPosition(device); return micPosition > length * i / isplit && micPosition < length * (i + 1) / isplit; });
        micDataTemp = new float[length / isplit];
        recordClip.GetData(micDataTemp, (i - 1) * length / isplit);
    }
    yield return new WaitUntil(() => { micPosition = Microphone.GetPosition(device); return micPosition < length / isplit; });//get the last part of the audio data
    micDataTemp = new float[length / isplit];
    recordClip.GetData(micDataTemp, (isplit - 1) * length / isplit);
}

Can't get data from streamed samples for audio clip "MySinusoid". If you created the audio clip with AudioClip.Create, set the 'stream' argument to false, so you can access the data with 'AudioClip.GetData'. For a disk-based audio clip, change the load type to 'DecompressOnLoad', so you can access the data with 'AudioClip.GetData'.
UnityEngine.AudioClip:GetData (single[],int)
xfHelper.xfAPIHelper/d__21:MoveNext () (at Assets/Scripts/Helper/xfHelper.cs:90)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

@martindevans
Copy link
Member

Sorry, but I'm not clear on what the issue is.

@jackyetz
Copy link
Author

Sorry, but I'm not clear on what the issue is.

i wanna get the acoustic echo cancelled microphone audio data, but failed. Can u help me. See above for the detailed error prompt

@martindevans
Copy link
Member

To get mic audio with AEC from Dissonance:

  1. Set up Dissonance AEC. (docs).
  2. Use BaseMicrophoneSubscriber or IMicrophoneSubscriber to access the recorded audio stream. (docs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants