Audio data processing method, system and device
By adjusting the time difference between the audio data acquisition modules in the smart device, the phase alignment of the audio data is achieved, and echo cancellation is performed, which solves the problems of beat beat and inaccurate recognition in speech recognition and improves the recognition accuracy.
Patent Information
- Application Number
- PCT/CN2024/082562
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-03-31
- Filing Date
- 2024-03-20
- Publication Date
- 2024-10-03
AI Technical Summary
In speech recognition, there are out-of-beat and phase misalignment problems between the audio data collected by smart devices and the reference audio data, leading to inaccurate and misidentified recognition, and jitter in the severity of out-of-beat due to changes in CPU load.
By determining the time difference between the audio playback acquisition function and the microphone acquisition function, adjusting the audio data to align its phases, and combining the adjusted audio data with the unadjusted audio data, the combined audio data is obtained for echo cancellation.
It achieves phase alignment of audio data, solves the beat problem, and improves the accuracy of speech recognition by combining audio data for echo cancellation.
Smart Images

Figure CN2024082562_03102024_PF_FP_ABST
Abstract
Description
Audio data processing method, processing system and processing device
[0001] This application claims priority to Chinese patent application number 202310350768.0, the contents of which are incorporated by reference into this application.
Technical field
[0002] The present application relates to the field of audio processing technology, and in particular to an audio data processing method, processing system, and processing device. [Background Technology]
[0003] In speech recognition, the audio data collected by smart devices often contains noise in addition to the target audio data, such as the audio data played by the audio playback module of the smart device (reference sound data). At this time, if you want to perform speech recognition on the collected audio data, there will be problems such as inaccurate recognition, misrecognition, and no recognition. In addition, due to the influence of the system or software in the smart device on the high short-term CPU occupancy rate, there is a beat problem between the collected audio data and the reference sound data. The beat phenomenon can be understood as the phase misalignment of the collected audio data and the reference audio data. Since the CPU load will change, the severity of the beat of the data collected each time is different, that is, the size of the beat is jittery.
[0004] [Summary of the invention]
[0005] The present application provides an audio data processing method, processing system, and processing device, which can solve the problem of beat and phase misalignment between two audio data, especially the misalignment problem with jitter caused by excessive CPU load, and then use the combined audio data obtained by combination to perform echo cancellation processing.
[0006] In order to solve the above technical problems, a technical solution adopted in the present application is: providing an audio data processing method, the method comprising: using an audio driver to determine the time difference between turning on the audio playback recapture function and turning on the microphone collection function, and obtaining the first audio data collected by the audio playback recapture function and the second audio data collected by the microphone collection function; adjusting one of the first audio data and the second audio data based on the time difference so that the phases of the adjusted audio data and the unadjusted audio data in the first audio data and the second audio data are aligned; combining the unadjusted audio data with the adjusted audio data to obtain combined audio data; and performing echo cancellation based on the combined audio data.
[0007] The method of adjusting one of the first audio data and the second audio data based on the time difference so that the phases of the adjusted audio data and the unadjusted audio data in the first audio data and the second audio data are aligned includes: determining one of the first audio data and the second audio data as the audio data to be adjusted and the other audio data as the reference audio data based on the time difference; and adjusting the audio data to be adjusted so that the phases of the adjusted audio data to be adjusted are aligned with the reference audio data.
[0008] The time difference is the difference between the time when the audio playback function is turned on and the time when the microphone collection function is turned on.
[0009] Wherein, based on the time difference, one of the first audio data and the second audio data is determined as the audio data to be adjusted, and the other audio data is determined as the reference audio data, including: if the difference value of the time difference is a negative number, the second audio data is used as the audio data to be adjusted, and the first audio data is used as the reference audio data; if the difference value of the time difference is a non-negative number, the first audio data is used as the audio data to be adjusted, and the second audio data is used as the reference audio data.
[0010] The method of adjusting the audio data to be adjusted so that the adjusted audio data is phase-aligned with the reference audio data includes: determining the number of bytes that the audio data to be adjusted differs from the reference audio data; and performing a data padding operation on the audio data to be adjusted based on the number of bytes so that the adjusted audio data to be adjusted is phase-aligned with the reference audio data.
[0011] Combining the unadjusted audio data with the adjusted audio data to obtain combined audio data includes: combining the unadjusted audio data with the adjusted audio data at a hardware abstraction layer to obtain combined audio data; or
[0012] The unadjusted audio data is combined with the adjusted audio data at the kernel layer to obtain combined audio data.
[0013] Combining the unadjusted audio data with the adjusted audio data to obtain combined audio data includes: obtaining a preset combined audio data format; the preset combined audio data format is composed of at least the following bytes, wherein the first byte is for the first left channel data of the second audio data, the second byte is for the first right channel data of the second audio data, the third byte is for the first left channel data of the first audio data, the fourth byte is for the first right channel data of the first audio data, the fifth byte is for the second left channel data of the second audio data, the sixth byte is for the second right channel data of the second audio data, the seventh byte is for the second left channel data of the first audio data, and the eighth byte is for the second right channel data of the first audio data; and combining the unadjusted audio data with the adjusted audio data according to the preset combined audio data format to obtain the combined audio data.
[0014] Before performing echo cancellation based on the combined audio data, the method includes: using the AudioRecord class to transfer the combined audio data to the echo cancellation function; and performing echo cancellation based on the combined audio data includes: using the echo cancellation function to perform echo cancellation on the combined audio data.
[0015] Among them, before adjusting one of the first audio data and the second audio data based on the time difference so that the phases of the adjusted audio data and the unadjusted audio data in the first audio data and the second audio data are aligned, it includes: obtaining an adjustment parameter received by the adjustment interface; and adjusting the time difference using the adjustment parameter.
[0016] In order to solve the above technical problems, another technical solution adopted in this application is: to provide an audio data processing system, which includes an audio playback and playback module, a microphone acquisition module, an audio driver and processing module.
[0017] Among them, the audio playback and recapture module is used to collect the first audio data; the microphone acquisition module is used to collect the second audio data; the audio driver is connected to the audio playback and recapture module and is used to determine the time difference between turning on the audio playback and recapture function of the audio playback and recapture module and turning on the microphone acquisition function of the microphone acquisition module, and to obtain the first audio data collected by the audio playback and recapture module and the second audio data collected by the microphone acquisition module; the processing module is connected to the audio playback and recapture module, the microphone acquisition module and the audio driver, and is used to adjust one of the first audio data and the second audio data based on the time difference, so that the phase between the adjusted audio data and the unadjusted audio data in the first audio data and the second audio data is aligned; and the unadjusted audio data is combined with the adjusted audio data to obtain combined audio data; and echo cancellation is performed based on the combined audio data.
[0018] The processing system further includes a first buffer, a second buffer, and a third buffer. The first buffer is connected to the audio playback and recollection module, the audio driver, and the processing module to buffer the first audio data; the second buffer is connected to the microphone acquisition module, the audio driver, and the processing module to buffer the second audio data.
[0019] The processing module is used to read the first audio data from the first buffer and the second audio data from the second buffer, and adjust one of the first audio data and the second audio data based on the time difference so that the phases of the adjusted audio data and the unadjusted audio data in the first audio data and the second audio data are aligned; and combine the unadjusted audio data with the adjusted audio data to obtain combined audio data, and cache the combined audio data in a third buffer, which is connected to the processing module.
[0020] In order to solve the above technical problems, another technical solution adopted in this application is: to provide an audio data processing device, which includes a memory and a processor, wherein the memory is used to store computer programs and the processor is used to execute the computer programs to implement the above audio data processing method.
[0021] The beneficial effects of the present application are: different from the existing technology, the present application provides a method for processing audio data, which can use the audio driver to determine the time difference between turning on the audio playback recapture function and turning on the microphone collection function, and obtain the first audio data collected by the audio playback recapture function and the second audio data collected by the microphone collection function; then, based on the time difference, one of the first audio data and the second audio data is adjusted to align the phases between the adjusted audio data and the unadjusted audio data in the first audio data and the second audio data; the unadjusted audio data is combined with the adjusted audio data to obtain combined audio data; finally, echo cancellation is performed based on the combined audio data. In the above manner, the first audio data and the second audio data can be aligned, solving the problem of beat and phase misalignment between the audio data collected by the audio playback recapture function and the audio data collected by the microphone collection function, and further combining the two audio data, the obtained combined audio data can be used for echo cancellation to eliminate the first audio data corresponding to the second audio data.
Brief Description of the Drawings
[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without inventive efforts. Among them:
[0023] FIG1 is a flow chart of a first embodiment of an audio data processing method provided by the present application;
[0024] FIG2 is a flow chart of an embodiment of step 12 provided in this application;
[0025] FIG3 is a flow chart of an embodiment of step 22 provided in this application;
[0026] FIG4 is a schematic diagram of an embodiment of an audio data combination method provided by the present application;
[0027] FIG5 is a flowchart of a second embodiment of the audio data processing method provided by the present application;
[0028] FIG6 is a schematic structural diagram of a first embodiment of an audio data processing system provided by the present application;
[0029] FIG7 is a schematic structural diagram of a second embodiment of an audio data processing system provided by the present application;
[0030] FIG8 is a structural diagram of an embodiment of an audio data processing device provided by the present application;
[0031] FIG9 is a schematic structural diagram of an embodiment of a computer-readable storage medium provided in the present application. [Specific implementation method]
[0032] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It will be understood that the specific embodiments described herein are only used to explain the present application, rather than to limit the present application. It should also be noted that, for ease of description, only some, rather than all, structures related to the present application are shown in the drawings. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0033] In speech recognition, the audio data collected by smart devices often contains noise in addition to the target audio data, such as the audio data (reference sound data) played by the audio playback module of the smart device. At this time, if you want to perform speech recognition on the collected audio data, there will be problems such as inaccurate recognition, misrecognition, and no recognition. In addition, due to the influence of the system or software in the smart device on the high short-term CPU occupancy rate, there is a beat problem between the collected audio data and the reference sound data. The beat phenomenon can be understood as the phase misalignment of the collected audio data and the reference audio data. Since the CPU load is variable, the severity of the beat of the data collected each time is different, that is, the size of the beat is jittery. Based on this, the present application proposes any of the following implementation methods to solve at least one of the above technical problems.
[0034] 1 , which is a flow chart of a first embodiment of an audio data processing method provided by the present application. The method includes:
[0035] Step 11: Use the audio driver to determine the time difference between starting the audio playback and recapture function and starting the microphone collection function, and obtain the first audio data collected by the audio playback and recapture function and the second audio data collected by the microphone collection function.
[0036] Specifically, the time difference is the difference between the time when the audio playback and recapture function of the audio playback and recapture module is enabled and the time when the microphone collection function of the microphone collection module is enabled.
[0037] Among them, the audio playback and collection module is a module for collecting audio data from the audio playback module. The audio playback module is referred to as module A, and the audio playback and collection module is referred to as module B. Module A can be turned on at any time to work. If module A is already turned on when module B is turned on, the audio data collected by module B is downlink audio data. If module A is not turned on when module B is turned on, the audio data collected by module B is silent data. For example, the audio data played by module A is "Xiao Ming Xiao Ming where are you?", if module A is already turned on when module B is turned on, the audio data collected by module B may be "Ming Xiao Ming where are you?", "Xiao Ming where are you?" or other; if module A is not turned on when module B is turned on, the audio data collected by module B is silent data.
[0038] The microphone acquisition module is used to collect audio data output by the user or audio data output by other audio devices / modules. It is worth noting that the second audio data collected by the microphone acquisition module can include the first audio data. For example, if the first audio data collected by the audio playback and playback module is "Where are you?", and at the same time, the user inputs the voice "Xiao Ming Xiao Ming", the second audio data collected by the microphone acquisition module is a mixture of "Xiao Ming Xiao Ming" and "Where are you?"
[0039] Optionally, the audio playback and acquisition module may be an auxiliary module in a device such as an in-vehicle device, a smartphone, a laptop computer, or a smart wearable device; and the microphone acquisition module may be a MIC (Microphone) device in a sound card in a smartphone, a laptop computer, or an in-vehicle device. In other words, the audio playback and acquisition function may be a function of acquiring audio playback data by activating / starting an auxiliary module in a device such as an in-vehicle device, a smartphone, a laptop computer, or a smart wearable device; and the microphone acquisition function may be an audio data acquisition function by activating / starting the MIC device in the sound card.
[0040] In some embodiments, the audio playback and microphone capture functions are enabled through software programs / programming codes.
[0041] In some embodiments, the audio driver is an Advanced-Linux-Sound-Architecture System-on-Chip (ALSA) SoC driver. The ALSA SoC driver can record the time when the audio playback and playback function is enabled and the time when the microphone capture function is enabled to determine the time difference. For example, if the audio playback and playback function is enabled at 6:00 PM and the microphone capture function is enabled at 6:02 PM, the time difference is 2 minutes.
[0042] In some embodiments, the accuracy of the time when the audio playback function is turned on and the time when the microphone acquisition function is turned on can be ensured by setting a spin lock (spin_lock_irqsave).
[0043] After enabling the audio playback and microphone capture functions, they will each capture corresponding audio data. For example, the audio playback and microphone capture functions capture first audio data, and second audio data. The second audio data often contains other audio data besides the audio playback data. Therefore, echo cancellation is required.
[0044] Step 12: Adjust one of the first audio data and the second audio data based on the time difference, so that the adjusted audio data and the unadjusted audio data in the first audio data and the second audio data are phase-aligned.
[0045] It is understandable that due to the time difference, there will be a phase misalignment between the first audio data and the second audio data. It is understandable that audio data is actually transmitted in the form of sound waves. The so-called phase refers to the position of a sound wave in different cycle stages, which is represented by 0 degrees, 90 degrees, 180 degrees, 270 degrees, and 360 degrees. The phase problem comes from the fact that the same sound source is collected by more than two acquisition modules. Due to the differences in the acquisition modules, a single sound source will have a time difference for different acquisition modules. The audio data that should have been received at the same time point will appear at different time points in different acquisition modules. This time difference produces a phase difference, that is, a phase misalignment.
[0046] Therefore, only one of the first audio data and the second audio data needs to be adjusted to achieve phase alignment with the other.
[0047] In some embodiments, referring to FIG. 2 , step 12 may be the following process:
[0048] Step 21: Based on the time difference, one of the first audio data and the second audio data is determined as the audio data to be adjusted, and the other audio data is determined as the reference audio data.
[0049] It can be understood that the time difference is the difference between the time when the audio playback and playback function is turned on and the time when the microphone collection function is turned on.
[0050] In some embodiments, one of the first audio data and the second audio data is determined as the baseline audio data by the difference between the time when the audio playback recapture function is turned on and the time when the microphone capture function is turned on, and the other audio data is adjusted based on the baseline audio data.
[0051] For example, when the difference between the time when the audio playback recapture function is turned on and the time when the microphone collection function is turned on is a negative number, the audio playback recapture function is turned on earlier than the microphone collection function. At this time, the second audio data collected by the microphone collection function will lose the first part of the audio data collected by the audio playback recapture function. Therefore, the first audio data collected by the audio playback recapture function will be used as the baseline audio data, and the second audio data collected by the microphone collection function will be used as the audio data to be adjusted.
[0052] That is, the audio data acquired by the function activated first is used as a reference to adjust the audio data acquired by the function activated later.
[0053] In some embodiments, when the difference between the time when the audio playback recapture function is turned on and the time when the microphone collection function is turned on is a non-negative number (zero or a positive number), it means that the time when the second audio data is collected using the microphone collection function after the microphone collection function is turned on will be slightly later than the time when the first audio data is collected using the audio playback recapture function after the audio playback recapture function is turned on.
[0054] When the difference is zero, it means that the audio playback recapture function and the microphone acquisition function are turned on at the same time. It is worth noting that due to factors such as air propagation, the time when the audio playback recapture function collects the first audio data will take precedence over the time when the microphone acquisition function collects the second audio data. At this time, the first audio data and the second audio data are not synchronized in time, so the second audio data is used as the reference audio data and the first audio data is used as the audio data to be adjusted. Of course, in other embodiments, differences in the installation positions of the hardware devices may also cause the first audio data and the second audio data to be phase-misaligned.
[0055] In some embodiments, before adjusting one of the first audio data and the second audio data, adjustment parameters received by the adjustment interface can be obtained, and the time difference determined above can be adjusted using these adjustment parameters. Then, based on the adjusted time difference, one of the first audio data and the second audio data can be adjusted to align the phases of the adjusted audio data and the unadjusted audio data in the first audio data and the second audio data. The adjustment parameters can be manually input, i.e., a user can use the adjustment interface to customize the time error caused by differences in the installation locations of the hardware devices.
[0056] Similarly, when the difference is a positive number, it means that the microphone collection function takes precedence over the audio playback and playback function. In addition to the influence of factors such as air propagation, the first audio data and the second audio data are also asynchronous in time. In order to align the first audio data and the second audio data, the second audio data is used as the reference audio data and the first audio data is used as the audio data to be adjusted. The first audio data is adjusted based on the time difference so that the first audio data and the second audio data are phase-aligned.
[0057] Step 22: Adjust the audio data to be adjusted so that the adjusted audio data is phase-aligned with the reference audio data.
[0058] It's understood that phase reflects time characteristics and represents a waveform with a periodic motion. For example, a sine wave's phase can vary from 0 to 360 degrees within a cycle. When two audio signals are mixed, if their phases are misaligned, they can cancel each other out, leading to signal loss.
[0059] Therefore, when it is determined that the phases of two audio data are not aligned, it is necessary to adjust the two audio data to achieve phase alignment to avoid signal loss and the like.
[0060] In some embodiments, referring to FIG3 , step 22 may be the following process:
[0061] Step 31: Determine the number of bytes that differ between the audio data to be adjusted and the reference audio data.
[0062] Specifically, due to the influence of CPU load fluctuations caused by the system or software, there is a difference between the time of turning on the audio playback and recapture function and the time of turning on the microphone collection function, which causes a beat difference between the first audio data collected by the audio playback and recapture function and the second audio data collected by the microphone collection function.
[0063] At this time, the number of bytes between the first audio data and the second audio data can be calculated by combining the time difference with the sampling frequency (f), format (format) and number of channels (channel). The specific steps are as follows (not shown):
[0064] S1: Calculate the amount of audio data stored in the first audio data within a first time, and calculate the amount of audio data collected in the second audio data within a second time.
[0065] Specifically, the amount of audio data per unit time is calculated using the formula “storage capacity = sampling frequency × number of sampling bits × number of channels × time / 8”.
[0066] Among them, the unit of sampling frequency is Hertz; the number of channels for mono is 1, the number of channels for dual is 2, and the number of channels for quad is 4; the sampling bit number of mono and dual is 16 bits; the unit of time is second (s).
[0067] For example, if the sampling frequency of a record is 44KHz, the sampling bit number is 16 bits, and the channel is stereo (2 channels), then the storage capacity required to store audio data in one minute (60 seconds) is: 44×1000×16×2×60 / 8=10560000 (bytes).
[0068] S2: Compare the amount of audio data of the first audio data stored in the first time with the amount of audio data of the second audio data stored in the second time to determine the byte difference between the first audio data and the second audio data.
[0069] Since there's a difference between the time the audio playback recapture function is enabled and the time the microphone capture function is enabled, this difference is used as the time difference. If this time difference is a negative number, it means the first audio data captured using the audio playback recapture function precedes the second audio data captured using the microphone capture function. In this case, the second time can be determined based on the first time, calculated by subtracting the first time from the time difference.
[0070] For example, if the first time is 5 seconds and the time difference is 1 second, then the second time is 4 seconds. Taking the sampling frequency as 44 kHz, the sampling bit number as 16 bits, and 2 channels as an example, the amount of data stored in the second audio data within 4 seconds is 44×1000×16×2×4 / 8=704000 bytes, and the amount of data stored in the first audio data within 5 seconds is 44×1000×16×2×5 / 8=880000 bytes. At this time, the byte difference between the first audio data and the second audio data is 880000-704000=176000 bytes.
[0071] Of course, the "time" in the formula can be directly converted into "time difference" for calculation, such as 44×1000×16×2×1 / 8=176000 bytes.
[0072] In addition, in some embodiments, the time difference is required to be less than or equal to 10 milliseconds, and the time difference is a non-negative number, that is, the time of starting the audio playback function to collect the first audio data lags behind the time of starting the microphone collection function to collect the second audio data.
[0073] Step 32: Performing a data padding operation on the audio data to be adjusted based on the number of bytes, so that the adjusted audio data to be adjusted is phase-aligned with the reference audio data.
[0074] Specifically, a zero padding operation is performed from the start position of the audio data to be adjusted according to the number of bytes, so that the adjusted audio data to be adjusted is aligned with the reference audio data.
[0075] In some embodiments, when the difference between the time when the audio playback recapture function is turned on and the time when the microphone acquisition function is turned on is a negative number, the first audio data is used as the baseline audio data and the second audio data is used as the audio data to be adjusted. At this time, corresponding silence data is inserted into the buffer corresponding to the microphone acquisition function. In some embodiments, the silence data is 0.
[0076] For example, the first audio data and the second audio data that are not aligned are:
[0077] Among them, REF represents the first audio data, MIC represents the second audio data, and "12345..." represents the audio data being played / captured. As can be seen from the above table, because the microphone capture function is turned on later than the audio playback and recapture function, when the first audio data is captured by the first audio data ("1" in the table), the second audio data does not capture the first audio data played by the first audio data. Therefore, when the first audio data is played to the fifth audio data ("5" in the table), the second audio data captures the fifth audio data, indicating that the second audio data is later than the first audio data. At this time, based on the first audio data, the number of bytes of the beat difference between the first audio data and the second audio data is determined to adjust the second audio data, such as padding the beginning of the audio data captured by the second audio data, as shown in the following table.
[0078] The aligned first audio data and second audio data are:
[0079] In some embodiments, when the difference between the time when the audio playback recapture function is turned on and the time when the microphone capture function is turned on is a non-negative number (zero or positive), the second audio data is used as the reference audio data and the first audio data is used as the audio data to be adjusted.
[0080] For example, the first audio data and the second audio data that are not aligned are:
[0081] Here, REF represents the first audio data, MIC represents the second audio data, and "123456..." represents the audio data being played / captured. As can be seen from the table above, when the first and second audio data are time-aligned (the difference is zero), there is still a problem of beat difference between the first and second audio data due to influences such as air propagation. Further alignment is still required. As can be seen from the table above, when the second audio data captures the first audio data ("1" in the table), the second audio data does not capture the first and second audio data played by the first audio data ("1" and "2" in the table). Therefore, when the second audio data captures the first audio data, the first audio data is played to the third audio data ("3" in the table), indicating that the first audio data takes precedence over the second audio data in time. The second audio data is then used as the reference audio data to determine the number of bytes of beat difference between the first and second audio data to adjust the first audio data, as shown in the table below.
[0082] The aligned first audio data and second audio data are:
[0083] Step 13: Combine the unadjusted audio data with the adjusted audio data to obtain combined audio data.
[0084] It can be understood that if the adjusted audio data is the first audio data and the unadjusted audio data is the second audio data, then after the first audio data and the second audio data are phase-aligned, the adjusted first audio data and the unadjusted second audio data can be combined to obtain combined audio data; if the adjusted audio data is the second audio data and the unadjusted audio data is the first audio data, then after the first audio data and the second audio data are phase-aligned, the adjusted second audio data and the unadjusted first audio data can be combined to obtain combined audio data.
[0085] In some embodiments, the phase-aligned first audio data and the second audio data are combined based on the Android system. The Android system includes four layers: the APP (Application) layer, the Framework layer, the HAL layer (also known as the Hardware Abstraction Layer), and the Kernel layer (also known as the kernel layer).
[0086] Specifically, the unadjusted audio data and the adjusted audio data can be combined based on the HAL layer, that is, the first audio data after phase alignment and the second audio data are combined to obtain combined audio data; the unadjusted audio data and the adjusted audio data can also be combined at the Kernel layer, that is, the first audio data after phase alignment and the second audio data are combined to obtain combined audio data.
[0087] For example, when combining the phase-aligned first audio data and second audio data at the HAL layer, it is necessary to first execute the read thread startup action for the audio playback and microphone acquisition functions at the HAL layer. After the microphone acquisition function and the audio playback and acquisition functions start the read threads, they enter a waiting state. Then, the HAL layer continuously triggers the waiting semaphores in the two read threads, causing the two read threads to start reading operations almost simultaneously. Then, using the logical operations of ALSA (Advanced Linux Audio Architecture), the read data will be returned when the read data reaches a preset amount. In addition, even if two read operation instructions are issued consecutively, there is still a time difference between the execution of the two instructions, and this time difference will change with the differences in system or software loading, resulting in different time differences.
[0088] It is worth noting that if it is necessary to combine the aligned first audio data and the second audio data at the HAL layer, the first audio data and the second audio data are read from the sound card device (sound card driver); if it is necessary to combine the aligned first audio data and the second audio data at the Kernel layer, the first audio data and the second audio data are directly read from the hardware.
[0089] In some embodiments, a preset combined audio data format is first acquired, and then the phase-aligned first audio data and the second audio data are combined based on the acquired preset combined audio data format to obtain combined audio data.
[0090] The combined audio data format may be a 4-channel combination of two audio zones or a 6-channel combination of four audio zones. The 4-channel combination refers to a left audio zone and a right audio zone, while the 4-channel combination refers to a front left audio zone, a front right audio zone, a rear left audio zone, and a rear right audio zone. The 4-channel combination refers to a 4-channel combination of two second audio data and two first audio data frames per frame. The 6-channel combination refers to a 6-channel combination of four second audio data and two first audio data frames per frame.
[0091] In some embodiments, the preset combined audio data format consists of at least the following bytes, wherein the first byte holds the first left channel data of the second audio data, the second byte holds the first right channel data of the second audio data, the third byte holds the first left channel data of the first audio data, the fourth byte holds the first right channel data of the first audio data, the fifth byte holds the second left channel data of the second audio data, the sixth byte holds the second right channel data of the second audio data, the seventh byte holds the second left channel data of the first audio data, and the eighth byte holds the second right channel data of the first audio data. As shown in FIG4 , FIG4 is an embodiment of a combination method of the first audio data and the second audio data.
[0092] The data format of the first audio data (2 channels) is:
[0093] REF represents first audio data, and the storage format of the audio data is LRLR (left-right-left).
[0094] The data format of the second audio data (2 channels) is:
[0095] MIC represents second audio data, and the storage format of the audio data is LRLR (left-right-left).
[0096] The data format of combined audio data (4 channels) is:
[0097] As described above, in this embodiment, the combined audio data composed of the first audio data and the second audio data is obtained by inserting the first audio data and the second audio data in turn.
[0098] It is worth noting that when aligning the first audio data and the second audio data, it is required to simultaneously start the read threads of the audio playback and microphone acquisition functions at the HAL layer (or Kernel layer) so that the audio playback and microphone acquisition functions can start reading data respectively. It is also required that the audio playback and microphone acquisition functions do not underrun or overrun during the data transmission process. If an overrun occurs, the buffer will be overwritten; if an underrun occurs, data will be lost. Whether an overrun or an underrun occurs, it will eventually cause the first audio data and the second audio data to be misaligned (beat difference).
[0099] In addition, the combination operation of the aligned first audio data and the second audio data is also completed at the HAL layer (or Kernel layer), requiring AudioRecord to start a read thread at the AudioFlinger layer to trigger the two read threads on the HAL layer, and start using the audio playback recapture function and the microphone acquisition function to read data, and cache the read data in their respective Ringbuffers. It is worth noting that the audio playback recapture function and the microphone acquisition function are always in a waiting state. When the buffer corresponding to the audio playback recapture function and the buffer corresponding to the microphone acquisition function have a first amount of data, a certain amount of data is read from the starting position of the buffers corresponding to the two functions respectively, and written to the destination buffer, so as to combine the aligned first audio data and the second audio data to obtain combined audio data. For example, after there is 5ms of data in the buffers corresponding to the two functions, 5ms of data is read from the starting position of the two buffers respectively and filled into the destination buffer.
[0100] Step 14: Perform echo cancellation based on the combined audio data.
[0101] In some embodiments, after the combined audio data is obtained, the combined audio data is transferred to the echo cancellation function using the AudioRecord (audio acquisition) class, so that the echo cancellation function performs echo cancellation on the combined audio data.
[0102] In other embodiments, the combined audio data may be delivered via a private interface or a callback.
[0103] In some embodiments, an ECNR (Echo Cancellation and Noise Reduction) algorithm is used to perform echo cancellation and noise reduction processing on the combined audio data to eliminate the first audio data corresponding to the second audio data.
[0104] Different from the existing technology, the audio data processing method provided in this application determines the time difference between turning on the audio playback recapture function and turning on the microphone collection function, and then adjusts one of the first audio data collected by the audio playback recapture function and the second audio data collected by the microphone collection function based on the time difference, so that the adjusted audio data and the unadjusted audio data in the first audio data and the second audio data are phase-aligned. Then, the unadjusted audio data is combined with the adjusted audio data to obtain combined audio data, and echo cancellation is performed based on the combined audio data. The above method can solve the problem of beat difference and misalignment between the first audio data and the second audio data, achieve alignment of the two audio data, and then combine the two aligned audio data to obtain combined audio data, so as to perform echo cancellation based on the combined audio data.
[0105] 5 , which is a flow chart of a second embodiment of an audio data processing method provided by the present application, the method comprising:
[0106] Step 51: using the audio driver to determine the time difference between starting the audio playback and recapture function and starting the microphone acquisition function, and obtaining the first audio data collected by the audio playback and recapture function and the second audio data collected by the microphone acquisition function.
[0107] Step 52: Based on the time difference, determine one of the first audio data and the second audio data as the audio data to be adjusted, and determine the other audio data as the reference audio data.
[0108] Step 53: Determine the number of bytes that differ between the audio data to be adjusted and the reference audio data.
[0109] Step 54: performing a data padding operation on the audio data to be adjusted based on the number of bytes, so that the adjusted audio data to be adjusted is aligned with the reference audio data.
[0110] Step 55: Determine the preset combined audio data format.
[0111] Specifically, the preset combined audio data format is provided by the manufacturer of the audio playback and playback module and the microphone acquisition module. The preset combined audio data consists of at least 8 bytes, wherein the first byte holds the first left channel data of the second audio data, the second byte holds the first right channel data of the second audio data, the third byte holds the first left channel data of the first audio data, the fourth byte holds the first right channel data of the first audio data, the fifth byte holds the second left channel data of the second audio data, the sixth byte holds the second right channel data of the second audio data, the seventh byte holds the second left channel data of the first audio data, and the eighth byte holds the second right channel data of the first audio data.
[0112] Step 56: Combine the unadjusted audio data and the adjusted audio data according to a preset combined audio data format to obtain combined audio data.
[0113] Step 57: Perform echo cancellation based on the combined audio data.
[0114] Steps 51 to 57 may have the same or similar technical solutions as any of the above embodiments, and will not be described in detail here.
[0115] Different from the existing technology, the audio data processing method provided in this application is based on the time difference between turning on the audio playback recapture function and turning on the microphone collection function. The first audio data collected using the audio playback recapture function or the second audio data collected using the microphone collection function is adjusted to align the phases of the first audio data and the second audio data. The first audio data and the second audio data after phase alignment are then combined to obtain combined audio data, so that echo cancellation can be performed based on the combined audio data.
[0116] In an application scenario of an in-vehicle device, the audio playback and acquisition module and the microphone acquisition module of the in-vehicle device are turned on. The in-vehicle device also has a voice recognition function. When the voice recognition function is turned on, it is necessary to determine the time difference between turning on the audio playback and acquisition module and turning on the microphone acquisition module; based on the time difference, the first audio data collected by the audio playback and acquisition module or the second audio data collected by the microphone acquisition module is adjusted to align the first audio data with the second audio data; the aligned first audio data and the second audio data are combined to obtain combined audio data; and echo cancellation is performed based on the combined audio data.
[0117] For example, the first audio data collected by the audio playback recapture function is "Where am I?", and at the same time, the user also voice-enters "Xiao Ming Xiao Ming", then the microphone capture function collects the second audio data that is a mixture of "Where am I" and "Xiao Ming Xiao Ming". At this time, it is necessary to determine the time difference between turning on the audio playback recapture function and turning on the microphone capture function; based on the time difference, adjust the first audio data collected by the audio playback recapture function or the second audio data collected by the microphone capture function to align the phases of the first audio data and the second audio data; combine the phase-aligned first audio data and the second audio data to obtain combined audio data; and perform echo cancellation based on the combined audio data. That is, eliminate "Where am I" in the second audio data to obtain "Xiao Ming Xiao Ming", and then determine whether to start voice recognition based on "Xiao Ming Xiao Ming".
[0118] Refer to Figure 6, which is a structural diagram of the first embodiment of the audio data processing system provided by this application. The audio data processing system 60 includes an audio playback and recollection module 601, a microphone collection module 602, an audio driver 603 and a processing module 604. Among them, the audio playback recapture module 601 is used to collect first audio data; the microphone acquisition module 602 is used to collect second audio data; the audio driver 603 is connected to the audio playback recapture module 601 and the microphone acquisition module 602, and is used to determine the time difference between starting the audio playback recapture function of the audio playback recapture module 601 and starting the microphone acquisition function of the microphone acquisition module 602, and to obtain the first audio data collected by the audio playback recapture module 601 and the second audio data collected by the microphone acquisition module 602; the processing module 604 is connected to the audio playback recapture module 601, the microphone acquisition module 602 and the audio driver 603, and is used to adjust one of the first audio data and the second audio data based on the time difference, so that the phase between the adjusted audio data and the unadjusted audio data in the first audio data and the second audio data is aligned, and to combine the unadjusted audio data with the adjusted audio data to obtain combined audio data, and perform echo cancellation based on the combined audio data.
[0119] Optionally, the audio playback and acquisition module 601 can be a vehicle-mounted device, a smart phone, a laptop computer, a smart wearable device, etc.; the microphone acquisition module 602 can be a MIC device of the sound card in a smart phone, a laptop computer, a vehicle-mounted device, etc.
[0120] In some embodiments, the audio playback and recapture module 601 and microphone acquisition module 602 can be directly connected to the main chip's ADC (Analog-to-Digital Converter) or standard I2S (Inter-IC Sound). In this case, the first audio data collected by the audio playback and recapture module 601 can be the audio data obtained after the audio data is transmitted back to the SoC (System-on-Chip) via I2S / ADC before being output.
[0121] In some embodiments, referring to FIG7 , the audio data processing system 60 may further include a first buffer 701, a second buffer 702, and a third buffer 703. The first buffer 701 is connected to the audio playback and recapture module 601, the audio driver 603, and the processing module 604, and is configured to buffer the first audio data. The second buffer 702 is connected to the microphone acquisition module 602, the audio driver 603, and the processing module 604, and is configured to buffer the second audio data. The processing module 604 is configured to read the first audio data from the first buffer 701 and the second audio data from the second buffer 702, adjust one of the first audio data and the second audio data based on a time difference so that the adjusted audio data and the unadjusted audio data are phase-aligned, combine the unadjusted audio data with the adjusted audio data to obtain combined audio data, and buffer the combined audio data in the third buffer 703. The third buffer 703 is connected to the processing module 604.
[0122] Refer to Figure 8, which is a structural diagram of an embodiment of an audio data processing device provided in the present application. The audio data processing device 80 includes a memory 801 and a processor 802. The memory 801 is used to store computer programs, and the processor 802 is used to execute computer programs to implement the audio data processing method as in any of the above embodiments, which will not be repeated here.
[0123] Refer to Figure 9, which is a structural diagram of an embodiment of a computer-readable storage medium provided in the present application. The computer-readable storage medium 90 stores a computer program 901. When the computer program 901 is executed by the processor, it is used to implement the audio data processing method as in any of the above embodiments, which will not be repeated here.
[0124] In summary, the audio data processing method provided in the present application can solve the problem of beat and phase misalignment between two audio data, and can use the combined audio data obtained by combining the two aligned audio data to perform echo cancellation.
[0125] The processor involved in this application can be called a CPU (Central Processing Unit), which may be an integrated circuit chip, or a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic device, or discrete hardware component.
[0126] The storage media used in this application include various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), or an optical disk.
[0127] The above description is only an implementation method of the present application and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the description and drawings of this application, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. An audio data processing method, characterized in that: The method comprises: Determine the time difference between starting the audio playback and recollection function and starting the microphone collection function by using the audio driver, and obtain the first audio data collected by the audio playback and recollection function and the second audio data collected by the microphone collection function; adjusting one of the first audio data and the second audio data based on the time difference so that the phases of the adjusted audio data and the unadjusted audio data in the first audio data and the second audio data are aligned; Combining the unadjusted audio data with the adjusted audio data to obtain combined audio data; Echo cancellation is performed based on the combined audio data.
2. The method according to claim 1, characterized in that: The step of adjusting one of the first audio data and the second audio data based on the time difference so that the phases of the adjusted audio data and the unadjusted audio data in the first audio data and the second audio data are aligned includes: Based on the time difference, determining one of the first audio data and the second audio data as the audio data to be adjusted, and determining the other audio data as the reference audio data; The audio data to be adjusted is adjusted so that the adjusted audio data to be adjusted is phase-aligned with the reference audio data.
3. The method according to claim 2, characterized in that The time difference is the difference between the time of starting the audio playback function and the time of starting the microphone collection function; The step of determining, based on the time difference, one of the first audio data and the second audio data as the audio data to be adjusted and the other audio data as the reference audio data comprises: If the time difference is a negative number, the second audio data is used as the audio data to be adjusted, and the first audio data is used as the reference audio data; If the time difference is a non-negative number, the first audio data is used as the audio data to be adjusted, and the second audio data is used as the reference audio data.
4. The method according to claim 2, characterized in that: The step of adjusting the audio data to be adjusted so that the adjusted audio data to be adjusted is phase-aligned with the reference audio data includes: Determine the number of bytes that the audio data to be adjusted differs from the reference audio data; A data padding operation is performed on the audio data to be adjusted based on the number of bytes, so that the adjusted audio data to be adjusted is phase-aligned with the reference audio data.
5. The method according to claim 1, characterized in that The step of combining the unadjusted audio data with the adjusted audio data to obtain combined audio data includes: combining the unadjusted audio data with the adjusted audio data at a hardware abstraction layer to obtain combined audio data; or, The unadjusted audio data is combined with the adjusted audio data at the kernel layer to obtain combined audio data.
6. The method according to claim 1, characterized in that The step of combining the unadjusted audio data with the adjusted audio data to obtain combined audio data includes: Obtain a preset combined audio data format; the preset combined audio data format is composed of at least the following bytes, wherein the first byte is for the first left channel data of the second audio data, the second byte is for the first right channel data of the second audio data, the third byte is for the first left channel data of the first audio data, the fourth byte is for the first right channel data of the first audio data, the fifth byte is for the second left channel data of the second audio data, the sixth byte is for the second right channel data of the second audio data, the seventh byte is for the second left channel data of the first audio data, and the eighth byte is for the second right channel data of the first audio data; The unadjusted audio data and the adjusted audio data are combined according to the preset combined audio data format to obtain combined audio data.
7. The method according to claim 6, characterized in that Before performing echo cancellation based on the combined audio data, the method includes: using the AudioRecord class to transfer the combined audio data to the echo cancellation function; The performing echo cancellation based on the combined audio data comprises: The echo cancellation function is used to perform echo cancellation on the combined audio data.
8. The method according to claim 1, characterized in that Before adjusting one of the first audio data and the second audio data based on the time difference so that the adjusted audio data and the unadjusted audio data in the first audio data and the second audio data are phase-aligned, the method includes: The adjustment parameter received by the adjustment interface is acquired, and the time difference is adjusted using the adjustment parameter.
9. An audio data processing system, characterized in that: The audio data processing system comprises: An audio playback and collection module, used for collecting first audio data; A microphone acquisition module, used for acquiring second audio data; An audio driver, connected to the audio playback and recollection module and the microphone acquisition module, for determining a time difference between starting the audio playback and recollection function of the audio playback and recollection module and starting the microphone acquisition function of the microphone acquisition module, and obtaining first audio data collected by the audio playback and recollection module and second audio data collected by the microphone acquisition module; A processing module is connected to the audio playback and collection module, the microphone collection module and the audio driver, and is used to adjust one of the first audio data and the second audio data based on the time difference, so that the adjusted audio data in the first audio data and the second audio data Phase alignment between the audio data and the unadjusted audio data; combining the unadjusted audio data with the adjusted audio data to obtain combined audio data; and performing echo cancellation based on the combined audio data.
10. The audio data processing system according to claim 9, characterized in that: The audio data processing system further comprises: A first buffer, the first buffer is connected to the audio playback and retrieving module, the audio driver and the processing module, and is used to buffer the first audio data; A second buffer, the second buffer is connected to the microphone acquisition module, the audio driver and the processing module, and is used to buffer the second audio data; The processing module is used to read the first audio data from the first buffer, and read the second audio data from the second buffer, and adjust one of the first audio data and the second audio data based on the time difference so that the phase between the adjusted audio data and the unadjusted audio data in the first audio data and the second audio data is aligned; and combine the unadjusted audio data with the adjusted audio data to obtain combined audio data, and cache the combined audio data in a third buffer; the third buffer is connected to the processing module.
11. An audio data processing device, characterized in that: The audio data processing device comprises a memory and a processor, wherein the memory is used to store a computer program, and the processor is used to execute the computer program to implement the method according to any one of claims 1 to 8.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store a computer program, and the computer program is used to implement the method according to any one of claims 1 to 8 when executed by a processor.
Citation Information
Patent Citations
Automatic aligning method for echo canceling data
CN101064530A
Multi-path audio-frequency data processing system
CN101075183A
Echo cancellation method and device
CN104394286A
Method and device for removing recording echo in real time
CN108573710A
Audio data processing method and system and storage medium
CN112509595A
