A method and system for fault detection and split reconstruction of dual-channel recording in a dynamic audio environment
By acquiring various audio detection information to accurately locate the fault path and perform branch reconstruction, the problem of fault detection and reconstruction of recording systems in dynamic audio environments is solved, ensuring the continuity and integrity of recordings.
Patent Information
- Application Number
- CN202611406860.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-10
- Publication Date
- 2026-11-24
AI Technical Summary
In dynamic audio environments, dual-channel recording systems cannot accurately locate faulty audio paths, leading to interrupted recording file writing or cross-device audio distortion, and lack an effective acquisition recovery confirmation mechanism.
By acquiring fault detection information such as audio device events, acquisition session status, device identifier polling results, branch frame arrival status, and local frame energy status of acquisition components, abnormal paths are identified. While keeping the non-abnormal paths running, the buffer status and format conversion status of the abnormal paths are cleared, the data callbacks of the abnormal paths are re-established, and the reconstruction is confirmed to be successful.
It enables precise location of fault paths and execution of branch reconstruction in dynamic audio environments, avoiding recording interruptions and resource waste, and ensuring the continuity and integrity of recordings.
Smart Images

Figure CN123161601A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of audio signal processing technology, and in particular to a method and system for fault detection and branch reconstruction of dual-channel recording in a dynamic audio environment. Background Technology
[0002] During desktop conference and call recording, it is necessary to simultaneously acquire both system audio and microphone audio signals, and then mix the two data streams and write them into the same recording file. During recording, users may plug or unplug headphones, switch Bluetooth devices, or connect an external microphone at any time. The operating system may also interrupt the audio acquisition session due to resource conflicts. These dynamic changes may cause the data stream of one audio signal to be interrupted while the other continues to work normally. The recording status indicator on the interface usually cannot reflect the actual acquisition status.
[0003] In existing technologies, dual-channel recording systems typically establish all acquisition paths at once when recording begins. When the device environment changes or an acquisition anomaly occurs, one approach is to rely on system device change notifications to trigger processing. However, device change notifications may be missed, and the fault cannot be detected when the device identifier has not changed but the data stream has been interrupted. Another approach is to restart the entire recording pipeline. However, this approach will cause the recording file writing to be interrupted, affecting the other channel that is working normally. Residual buffered data and resampler status can also cause cross-device audio distortion, and there is a lack of an effective confirmation mechanism for whether the reconstructed acquisition has actually been restored.
[0004] How to accurately locate the faulty audio path during dual-channel recording, perform branch reconstruction only on that path without affecting the writing of the normal path and output file, and effectively confirm that the acquisition has been actually restored after reconstruction is a technical problem that urgently needs to be solved in this field. Summary of the Invention
[0005] To address the aforementioned problems, this application provides a method and system for fault detection and branch reconstruction of dual-channel recording in a dynamic audio environment, comprising the following: In a first aspect, this application provides a method for fault detection and branch reconstruction of dual-channel recording in a dynamic audio environment, the method comprising: The first audio data is obtained through the first acquisition interface, and the second audio data is obtained through the second acquisition interface. The first audio data and the second audio data are converted into a unified target format and sent into the same audio writing pipeline. Acquire fault detection information, which includes at least two of the following: audio device events, acquisition session status, device identifier polling results, split frame arrival status, and local frame energy status of the acquisition component. The path to which the anomaly belongs is determined based on the fault detection information, and the path is either the first audio path or the second audio path; Keep the non-abnormal path and the audio write pipeline running, stop the abnormal path, and clear the buffer state, format conversion state and playback scheduling state of the abnormal path. The abnormal path is re-established according to the current audio device status, the data callback of the reconstructed abnormal path is restored, and the reconstruction is confirmed to be successful after a new audio frame is detected in the reconstructed abnormal path. When reconstruction fails, the number of retries is accumulated, and an error status is output after the number of retries reaches a preset upper limit.
[0006] Optionally, obtaining fault detection information includes: When acquiring the audio device event, receive the default output device change event; When obtaining the acquisition session status, receive acquisition session interruption event, interruption end event, or runtime error event; When obtaining the device identifier polling result, the current input device identifier and the current output device identifier are compared with the recorded baseline identifier at a preset period. When obtaining the arrival status of the split frame, the timestamps of the most recent positive frame data received by the first audio path and the second audio path are recorded respectively. When acquiring the local frame energy state of the acquisition component, the cumulative frame progress and average energy of the process audio capture unit are detected according to a preset period.
[0007] Optionally, clearing the buffer state, format conversion state, and playback scheduling state of the abnormal path includes: When the abnormal path is a system audio path based on the process audio interception unit, clear the cumulative buffer, resampler buffer and player queue of the system audio path, and set the fade-in state after reconstruction. When the abnormal path is a microphone path based on an independent audio acquisition session, stop the acquisition session of the microphone path, remove the session observer, clear the acquisition object and the accumulated buffer, and reacquire the default input device after a preset device stabilization time.
[0008] Optionally, the method further includes: When a change in the input sampling rate of the first or second audio data is detected, the cumulative buffer and format conversion cache of the corresponding path are cleared, and subsequent audio data is resampled to the unified target format.
[0009] Optionally, the method further includes: After recording stops, read the duration of the output audio media; If the media duration reading fails or the media duration is not positive, the estimated duration is calculated based on the cumulative number of written frames and the target sampling rate.
[0010] Optionally, re-establishing the abnormal path based on the current audio device status includes: After the device status stabilizes, the corresponding path acquisition is re-established based on the current default audio device.
[0011] Optionally, detecting that the reconstructed abnormal path generates a new audio frame includes: After the data callback of the reconstructed abnormal path is received, it is monitored whether the data callback of the path receives a new audio frame. The arrival of the new audio frame is used as a confirmation sign that the abnormal path reconstruction is successful.
[0012] Secondly, this application provides a fault detection and branch reconstruction system for dual-channel recording in a dynamic audio environment, the system comprising: The acquisition and processing unit is used to obtain a first audio data channel through a first acquisition interface and a second audio data channel through a second acquisition interface, convert the first audio data channel and the second audio data channel into a unified target format and send them into the same audio writing pipeline. The detection unit is used to acquire fault detection information, which includes at least two of the following: audio device events, acquisition session status, device identifier polling results, multi-path frame arrival status, and local frame energy status of the acquisition component. A classification unit is used to determine the path to which the anomaly belongs based on the fault detection information, wherein the path is a first audio path or a second audio path; The isolation and cleanup unit is used to keep the non-abnormal path and the audio writing pipeline running, stop the abnormal path, and clean up the buffer state, format conversion state and playback scheduling state of the abnormal path. The reconstruction unit is used to reconstruct the abnormal path according to the current audio device status and restore the data callback of the reconstructed abnormal path. The confirmation unit is used to confirm that the reconstruction was successful after detecting that a new audio frame was generated in the reconstructed abnormal path. The retry control unit is used to accumulate the number of retries when reconstruction fails, and output an error status after the number of retries reaches a preset upper limit.
[0013] Optionally, the detection unit acquires various types of fault detection information, including: When acquiring the audio device event, receive the default output device change event; When obtaining the acquisition session status, receive acquisition session interruption event, interruption end event, or runtime error event; When obtaining the device identifier polling result, the current input device identifier and the current output device identifier are compared with the recorded baseline identifier at a preset period. When obtaining the arrival status of the split frame, the timestamps of the most recent positive frame data received by the first audio path and the second audio path are recorded respectively. When acquiring the local frame energy state of the acquisition component, the cumulative frame progress and average energy of the process audio capture unit are detected according to a preset period.
[0014] Optionally, the isolation and cleanup unit cleans up the buffer state, format conversion state, and playback scheduling state of the abnormal path, including: When the abnormal path is a system audio path based on the process audio interception unit, clear the cumulative buffer, resampler buffer and player queue of the system audio path, and set the fade-in state after reconstruction. When the abnormal path is a microphone path based on an independent audio acquisition session, stop the acquisition session of the microphone path, remove the session observer, clear the acquisition object and the accumulated buffer, and reacquire the default input device after a preset device stabilization time.
[0015] Optionally, the system further includes: The sampling rate protection unit is used to clear the cumulative buffer and format conversion cache of the corresponding path when it detects a change in the input sampling rate of the first audio data or the second audio data, and to resample the subsequent audio data to the unified target format.
[0016] Optionally, the system further includes: The file verification unit is used to read the media duration of the output audio after recording stops, and to calculate and estimate the duration based on the cumulative number of written frames and the target sampling rate when the media duration reading fails or the media duration is not positive.
[0017] Optionally, the reconstruction unit reconstructs the abnormal path based on the current audio device status, including: After the device status stabilizes, the corresponding path acquisition is re-established based on the current default audio device.
[0018] Optionally, the confirmation unit detects that the reconstructed abnormal path generates a new audio frame, including: After the data callback of the reconstructed abnormal path is received, it is monitored whether the data callback of the path receives a new audio frame. The arrival of the new audio frame is used as a confirmation sign that the abnormal path reconstruction is successful.
[0019] Thirdly, this application provides an apparatus comprising a memory and a processor, the memory for storing instructions or code, and the processor for executing the instructions or code to cause the apparatus to perform the fault detection and split-channel reconstruction method for dual-channel recording in a dynamic audio environment as described in any implementation of the first aspect.
[0020] Fourthly, this application provides a computer-readable storage medium storing code, wherein when the code is executed, a device running the code implements the fault detection and split-channel reconstruction method for dual-channel recording in a dynamic audio environment as described in any of the implementations of the first aspect.
[0021] This application provides a fault detection and branch reconstruction method for dual-channel recording in a dynamic audio environment. When executing the method, firstly, first and second audio data are obtained through a first acquisition interface and a second acquisition interface, respectively. The two audio data are converted into a unified target format and sent to the same audio write pipeline. Then, fault detection information is obtained, including at least two of the following: audio device events, acquisition session status, device identifier polling results, branch frame arrival status, and local frame energy status of the acquisition component. Next, the path to which the anomaly belongs is determined based on the fault detection information; the path is either the first audio path or the second audio path. Then, the non-abnormal path and the audio write pipeline continue to run, the abnormal path is stopped, and the buffer state, format conversion state, and playback scheduling state of the abnormal path are cleared. Subsequently, the abnormal path is re-established according to the current audio device state, and the data callback of the reconstructed abnormal path is restored. Finally, the detection of a new audio frame generated by the reconstructed abnormal path is used as a confirmation of successful reconstruction. When reconstruction fails, the number of retries is accumulated, and an error status is output after reaching a preset upper limit.
[0022] In this way, after determining the path to which the anomaly belongs through multi-source detection information, only the faulty path is reconstructed. This ensures that non-abnormal paths and the audio write pipeline are unaffected during the reconstruction process, achieving the effect of maintaining recording continuity and integrity in dynamic audio environments. Thus, faulty paths can be accurately located and reconstructed separately during dual-channel recording, avoiding data interruptions and resource waste caused by restarting the entire recording pipeline. Attached Figure Description
[0023] To more clearly illustrate the technical solutions in this embodiment or the prior art, the drawings used in the description of the embodiment or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0024] Figure 1 A flowchart illustrating a fault detection and split-channel reconstruction method for dual-channel recording in a dynamic audio environment, provided as an embodiment of this application; Figure 2 This is a schematic diagram of a fault detection and branch reconstruction device for dual-channel recording in a dynamic audio environment, provided in an embodiment of this application. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0026] Figure 1 This is a flowchart illustrating a fault detection and branch-path reconstruction method for dual-channel recording in a dynamic audio environment, provided as an embodiment of this application. (Combined with...) Figure 1 As shown in the embodiments of this application, the fault detection and branch reconstruction method for dual-channel recording in a dynamic audio environment may include: S101. Obtain first audio data through the first acquisition interface and second audio data through the second acquisition interface. Convert the first audio data and the second audio data into a unified target format and send them into the same audio writing pipeline.
[0027] The first audio data stream is system audio data, i.e., the audio output of the remote call subject. Its acquisition is based on a process audio data acquisition interface, such as the process audio data acquisition interface in macOS, implemented using Tap. The process audio data acquisition interface is an interface provided by the operating system for acquiring audio output data from a specified process. In actual implementation, it scans the processes currently outputting audio, selects target processes that do not belong to the exclusion set, creates a process audio data acquisition interface, a private aggregation device, and input / output callbacks, and converts the acquired multi-channel audio data into mono floating-point PCM data. In one possible implementation, for a running conferencing application, the audio frames output by the application are acquired through the process audio data acquisition interface; these audio frames carry the voice signal of the remote call subject.
[0028] The second audio data stream is microphone audio data, i.e., the local user's voice input, which is acquired based on a separate audio acquisition session. An audio acquisition session is a session object provided by the operating system for managing data streams from audio input devices. In the actual implementation, an audio acquisition session is created and data from the default input device is obtained.
[0029] The audio data acquired from the two paths may differ in format. The system performs sampling rate checks and mono conversion on both data streams separately, and then uses a resampler to unify them to the same target sampling rate. After format unification, the two audio data streams are sent to the mixer bus, where the mixer mixes the two data streams and writes them to the same output file. After successful file writing, the same PCM buffer is simultaneously used as a real-time transcription bridge input, ensuring that the data written to the disc comes from the same source as the data processed in real time. Figure 2 This is a schematic diagram of the overall architecture of a dual-channel recording system provided in an embodiment of this application. Figure 2 The diagram shows the structural relationship where the system audio path and microphone path are converted into their respective formats and then converged in the mixer and written to the same file.
[0030] By acquiring two audio data streams separately and converting them into a unified target format before sending them to the same audio writing pipeline, the two data streams are ensured to have the same format before entering the mixer, avoiding processing errors caused by format mismatch. On the other hand, writing them to the same file ensures the integrity of the recording output file, so that the final generated recording file contains complete dual-channel audio content, which is convenient for subsequent playback and transcription.
[0031] S102. Obtain fault detection information, which includes at least two of the following: audio device events, acquisition session status, device identifier polling results, branch frame arrival status, and local frame energy status of the acquisition component.
[0032] Acquiring fault detection information includes receiving a default output device change event when acquiring the audio device event. The default output device refers to the hardware device currently selected as the audio output destination in the operating system. A default output device change event is a device change notification sent from the operating system's underlying hardware abstraction layer to the upper-layer application when the user plugs or unplugs headphones, connects or disconnects a Bluetooth audio device, or manually switches the sound output device. In actual implementation, a listener for default output device change events is registered. Once this event is received, it indicates that the user may have switched the audio output device, and the system audio acquisition path originally established based on the old device may have become invalid. In one possible implementation, after the default output device is switched from the built-in speaker to Bluetooth headphones, the original process audio data acquisition interface still points to the old audio output path, making it unable to acquire data from the new Bluetooth headphone output path, thus triggering a fault determination of the system audio path.
[0033] When acquiring the acquisition session status, the system receives acquisition session interruption events, interruption end events, or runtime error events. An acquisition session interruption event is triggered when the audio acquisition session is actively paused by the system due to system resource conflicts or device preemption. An interruption end event is triggered when the paused acquisition session resumes operation. A runtime error event is triggered when a low-level error such as device unavailability or buffer overflow occurs during the acquisition session's operation. In actual implementation, the system acts as an observer of the acquisition session, receiving at least one of these three types of events. Receiving an acquisition session interruption event or a runtime error event indicates a possible abnormality in the microphone path; receiving an interruption end event indicates that the abnormality has ended and the acquisition session has resumed. In one possible implementation, when another application temporarily occupies the microphone, causing the acquisition session to be interrupted by the system, the system receives an interruption event and determines that the microphone path is abnormal.
[0034] When obtaining the device identifier polling result, the current input device identifier and the current output device identifier are compared with the recorded baseline identifier at a preset period. The device identifier is a unique identifier assigned by the operating system to each audio device; different devices have different identifiers. The baseline identifier is the initial device identifier recorded when recording starts. In actual implementation, the identifiers of the current default input device and the current default output device are read every preset period (e.g., 5 seconds) and compared with the baseline identifier recorded when recording starts. If the current identifier is inconsistent with the baseline identifier, it indicates that the user has switched audio devices. By periodically polling the device identifier, device changes can still be detected even if device change event notifications are lost. In one possible implementation, the default output device identifier recorded when recording starts is the UID of the built-in speaker. After the user connects a Bluetooth headset, polling reveals that the current default output device identifier has changed to the Bluetooth headset's UID; the two are inconsistent, triggering a fault determination in the system's audio path.
[0035] When obtaining the arrival status of the split-path frames, the timestamps of the most recent positive frame count data received by the first audio path and the second audio path are recorded respectively. Positive frame count data refers to audio frames containing valid audio samples, whose frame count is greater than zero. In actual implementation, a timestamp variable is maintained for the first audio path and the second audio path respectively. Each time the corresponding data callback function is called and the number of received audio frames is greater than zero, the timestamp is updated to the current system time. Every preset period (e.g., 5 seconds), the difference between the current time and the most recent timestamp is checked. If the difference exceeds a preset duration (e.g., 10 seconds), it indicates that the corresponding path has not received valid audio frames for a continuous period, and the path is determined to have a flow anomaly. It should be noted that the split-path heartbeat determines whether audio frames are continuously received, but does not determine whether the frames contain audible sound. In one possible implementation, the microphone path continuously receives audio frames normally after recording begins, and the timestamp is continuously updated. When the user unplugs the external microphone and the system does not switch to the built-in microphone in time, the data callback of the microphone path is no longer called, the timestamp stops updating, and after a preset duration, the system determines that the microphone path is abnormal.
[0036] When acquiring the local frame energy state of the acquisition component, the cumulative frame progress and average energy of the process audio capture unit are detected at preset intervals. The cumulative frame progress refers to the number of audio frames processed since the creation of the current generation of the process audio data acquisition interface. If the cumulative frame progress does not increase within consecutive preset intervals, it indicates that the interface has stopped outputting data. The average energy refers to the squared mean of the amplitudes of audio frames within the current detection interval, used to determine whether the audio frame contains a substantial sound signal. In actual implementation, the cumulative frame progress and average energy are checked every second. When no new frames are detected for 5 consecutive seconds, i.e., the cumulative frame progress remains unchanged for multiple consecutive detection intervals, a reselection of the audio output target is triggered; alternatively, a reselection of the audio output target is also triggered when the current generation of the process audio data acquisition interface has never detected non-zero energy and the low energy state lasts for 10 seconds. It should be noted that the low energy condition only takes effect when the current generation of the process audio data acquisition interface has never observed non-zero energy, therefore it is not applicable to the general detection of all subsequent silent scenarios. In one possible implementation, the audio frames output by the conferencing application when playing remote audio have a high average energy. When the conferencing application pauses audio output due to network lag, the cumulative frame progress of the process audio data acquisition interface stops increasing. After detecting no new frames for 5 consecutive seconds, the target process that is currently outputting audio is reselected.
[0037] By employing five complementary detection sources, various types of audio faults can be covered. Audio device events capture user-initiated device switching behavior; session events detect changes in the microphone's session lifecycle; device identifier polling compensates for potential missed device change notifications; heartbeat detection of split-path frames indicates silent faults where the device identifier hasn't changed but the data stream has been interrupted; and the local frame energy state detection of the acquisition component detects the failure of the target process in the audio data acquisition interface. These five detection sources cross-monitor two audio paths from different dimensions. The failure or omission of a single detection source will not prevent the fault from going completely undetected, thus improving the robustness and reliability of fault detection.
[0038] S103. Determine the path to which the abnormality belongs based on the fault detection information, wherein the path is either the first audio path or the second audio path.
[0039] In practical implementation, different detection sources carry different path context information when triggered. When the fault detection information originates from a default output device change event or an output device identifier change in the device identifier polling result, since the output device change only affects the system audio acquisition and does not affect the microphone input acquisition, the anomaly is attributed to the first audio path. When the fault detection information originates from an acquisition session interruption event, an interruption end event, or a runtime error event, since these events directly originate from the microphone acquisition session, the anomaly is attributed to the second audio path. When the fault detection information originates from a split frame arriving at the heartbeat and the detected timeout is for a frame arrival timestamp from the first audio path, the anomaly is attributed to the first audio path; if the timestamp from the second audio path times out, it is attributed to the second audio path. When the fault detection information originates from the local frame energy state of the acquisition component, since this detection targets the process audio data acquisition interface, the anomaly is attributed to the first audio path. In one possible implementation, a default output device change event and a split frame arrival heartbeat timeout information are received simultaneously. The default output device change event indicates a change in the output device, and the split frame arrival heartbeat timeout indicates that there are no new frames in the first audio path. The two corroborate each other, and the anomaly is determined to be in the first audio path.
[0040] By accurately attributing anomalies to specific audio paths, a blind overall restart at the entire recording system level is avoided. This allows recovery actions to be applied precisely to the path where the fault actually occurred, improving the efficiency of fault handling.
[0041] S104. Keep the non-abnormal path and the audio writing pipeline running, stop the abnormal path, and clear the buffer state, format conversion state and playback scheduling state of the abnormal path.
[0042] Once the faulty path is identified, for non-faulty paths, their acquisition sessions continue to run, and their audio data continues to be input to the mixer and written to the output file, unaffected by the reconstruction operation of the faulty path. The audio write pipeline, as a module independent of the two acquisition paths, continuously writes the mixed data to the output file, remaining operational throughout the reconstruction process. For faulty paths, data acquisition for that path is first stopped, and then the buffer state, format conversion state, and playback scheduling state of that path are cleared to prevent residual data from the old device from interfering with or distorting the data from the new device.
[0043] The process of clearing the buffer state, format conversion state, and playback scheduling state of the abnormal path includes: When the abnormal path is a system audio path based on the process audio capture unit, the cumulative buffer, resampler buffer, and player queue of the system audio path are cleared, and the reconstructed fade-in state is set. The cumulative buffer refers to the cache of audio sample data accumulated since the start of recording. Clearing this buffer prevents data from the old device from being mixed into the acquisition results of the new device. The resampler buffer is the cache of historical samples maintained internally by the resampler for interpolation calculations when processing audio data. Clearing this cache prevents historical samples at different sampling rates from affecting the resampling accuracy of the current data. The player queue is the queue structure used to transfer audio data from the acquisition thread to the mixer thread. Clearing this queue ensures that the new data after reconstruction is not mixed with the old data before reconstruction. The reconstructed fade-in state refers to the gradual amplification of the amplitude of the first few audio frames at the start of the reconstructed acquisition, avoiding popping sounds caused by sudden amplitude changes during reconstruction. In one possible implementation, the sampling rate record is also reset as a cleanup object; after clearing, the new audio frames will re-establish processing parameters based on the actual sampling rate of the current device.
[0044] When the abnormal path is a microphone path based on an independent audio acquisition session, the acquisition session for that microphone path is stopped, the session observer is removed, the acquisition object and accumulated buffer are cleared, and the default input device is reacquired after a preset device stabilization time. Stopping the acquisition session means calling the session stop interface provided by the operating system to terminate the acquisition session. Removing the session observer means canceling its role as an event listener for this acquisition session to prevent interference events from the old session from being received during reconstruction. Clearing the acquisition object means releasing the acquisition session object and its associated resources. The accumulated buffer refers to the buffer area for accumulated audio sample data stored on this path; clearing this buffer prevents data from the old microphone from being mixed into the new data after reconstruction. The preset device stabilization time is to ensure that the hardware device reaches a stable working state after switching or reinitialization.
[0045] By thoroughly cleaning up the buffer state, format conversion state, and playback scheduling state of abnormal paths before reconstruction, the audio distortion that may be caused by residual data across devices and sampling rates is eliminated, resulting in smooth, continuous, and distortion-free audio data after reconstruction.
[0046] S105. Re-establish the abnormal path according to the current audio device status, restore the data callback of the reconstructed abnormal path, and confirm the successful reconstruction after detecting that the reconstructed abnormal path generates a new audio frame.
[0047] Path reconstruction requires rebuilding the complete acquisition link based on the current audio device status, including waiting for the device status to stabilize, recreating the acquisition interface or session, re-registering callback functions, and rebuilding the buffer and player, among other steps.
[0048] The step of re-establishing the abnormal path based on the current audio device status includes: waiting for the device status to stabilize, and then re-establishing the acquisition of the corresponding path based on the current default audio device. Device stability means that after the audio hardware has switched or re-initialized, its sampling rate, number of channels, data stream status, and other parameters have reached a state where normal acquisition is possible. Reconstruction is not performed immediately after detecting a device change; instead, a preset stabilization time (e.g., 500 milliseconds) is waited to avoid performing multiple invalid reconstruction operations when the device changes rapidly and continuously. After the stabilization wait, if the abnormal path is a system audio path, the process audio data acquisition interface is recreated based on the current default output device, scanning the currently outputting audio process and selecting the target process; if the abnormal path is a microphone path, the audio acquisition session is recreated based on the current default input device.
[0049] The detection of new audio frames generated by the reconstructed abnormal path includes: after the data callback for the reconstructed abnormal path is restored, monitoring whether the data callback for that path receives a new audio frame, using the arrival of the new audio frame as a confirmation flag for the successful reconstruction of the abnormal path. A data callback function is registered with the operating system during path reconstruction, and this callback function is invoked when a new audio frame is generated on the path. After reconstruction is complete, an acknowledgment timer is started to monitor whether the callback function is invoked and whether an audio frame with a frame count greater than zero is received. Only when at least one new audio frame arrives is the reconstruction confirmed as successful, and the reconstruction attempt count is reset to zero and the device baseline identifier is updated. This confirmation mechanism distinguishes between the two states of "reconstruction initiated" and "acquisition resumed." In one possible implementation, the system audio path is reconstructed after the user switches output devices. After reconstruction is complete, if the callback function of the process audio data acquisition interface receives a new audio frame, the reconstruction is confirmed as successful, and the UID of the current default output device is updated to the new baseline identifier.
[0050] Using the arrival of a new audio frame as a confirmation of successful reconstruction avoids misjudging "initiating reconstruction operation" as "acquisition has been restored", ensuring the authenticity and reliability of the status report, and also providing an accurate basis for subsequent retry mechanisms.
[0051] S106. When reconstruction fails, accumulate the number of retries, and output an error status after the number of retries reaches a preset upper limit.
[0052] Reconstruction failure refers to the failure to detect a new audio frame within a preset timeout period after the reconstruction operation is executed. A global counter is maintained for each reconstruction attempt, and this counter is incremented by one each time a reconstruction attempt fails. When the number of retries reaches a preset limit (e.g., 3 times), reconstruction attempts are stopped, and an error status is output. This error status can be captured by upper-layer applications and used to display recording error prompts to the user or to implement other error handling strategies. When reconstruction is successful, the retry count is reset to zero so that the counting restarts for the next failure. In one possible implementation, the system audio path is reconstructed due to the exit of the target process. After the first reconstruction failure, the retry counter becomes 1, waits, and then attempts to reconstruct again. If no new frames are received for 3 consecutive attempts, an error status indicating a system audio acquisition failure is output.
[0053] By accumulating the number of retries and outputting an error status after reaching the limit, infinite retries are avoided in unrecoverable fault scenarios, saving system resources. At the same time, it ensures that upper-layer applications can be aware of the continuous abnormal status, making it easier to provide timely feedback to users or implement degradation strategies.
[0054] In this embodiment of the application, when a change in the input sampling rate of the first audio data or the second audio data is detected, the cumulative buffer and format conversion buffer of the corresponding path are cleared, and the subsequent audio data is resampled to the unified target format.
[0055] The input sampling rate refers to the actual sampling rate currently used by the audio device. When a user switches audio devices, the old and new devices may use different sampling rates. In one possible implementation, the old device has a sampling rate of 44.1kHz, and the new device has a sampling rate of 48kHz. If the resampling buffer is not cleared, the 44.1kHz historical samples buffered inside the resampler and the currently input 48kHz new samples will produce incorrect sampling points during interpolation calculations, resulting in frequency distortion or noise in the output audio.
[0056] The specific implementation of sample rate change protection is as follows: When a discrepancy is detected between the sample rate reported by the current audio device and the previously recorded sample rate, the accumulated buffer of that path is first cleared to prevent audio samples from the old and new sample rates from mixing in the buffer. Then, the internal buffer of the resampler is cleared to ensure that the resampler restarts processing in a clean initial state after the input sample rate change. Subsequently, the actual sample rate of the current default audio device is detected. For narrowband devices that may have abnormal sample rate markings, a corrected input sample rate is selected based on the device report value and runtime characteristics before resampling to a unified target format. On the audio data re-entering after the sample rate change, a short fade-in is applied to further smooth out the subtle phase discontinuities caused by the sample rate switch.
[0057] By using a sampling rate change protection mechanism, the old data in the cache and the resampler state are actively cleared when the sampling rate changes due to device switching. This eliminates audio distortion and interpolation errors caused by cross-sampling rate splicing, ensuring that the audio data before and after the sampling rate change have a consistent time base and format parameters during mixing.
[0058] In this embodiment, after recording stops, the media duration of the output audio is read. If the media duration reading fails or the media duration is not positive, the estimated duration is calculated based on the cumulative number of written frames and the target sampling rate.
[0059] When recording stops, each acquisition and processing component is stopped sequentially according to a preset order. First, the system audio path's process audio data acquisition interface is stopped to block new system audio input. Then, the mixing and file writing engine is stopped, finalizing any audio data not yet written to the mixer buffer and flushing it to the output file. Finally, the microphone path's audio acquisition session is stopped. This stopping sequence ensures that both data inputs have stopped before file finalization, avoiding incomplete file writing issues.
[0060] Media duration refers to the total length of the output audio file on the playback timeline, measured in seconds. After the file is finalized, the media duration of the output audio is read through the media resource interface. If the duration reading fails or the read duration is not positive, the duration information in the file header cannot be relied upon. In this case, the estimated duration is calculated by dividing the cumulative number of audio frames written during recording by the target sampling rate. The specific calculation formula is: Estimated duration = Cumulative number of written frames / Target sampling rate. It should be noted that a positive duration only proves that the output file has a resolvable timeline, and does not necessarily prove that it contains non-silent or semantically valid audio. In one possible implementation, if the recording duration is 1 hour, the target sampling rate is 48kHz, and the cumulative number of written frames is 172,800,000, then the estimated duration = 172,800,000 / 48,000 = 3600 seconds, which is consistent with the actual 1 hour.
[0061] By performing dual verification of media duration after recording stops, the timeline information of the output audio can still be obtained even when the file header information is unavailable. This information is used to determine whether the output file has formed a valid audio timeline. Successful media duration reading indicates that the output file has a parsable timeline, while in case of reading failure, the duration is estimated by accumulating the number of written frames, providing a fallback verification method.
[0062] The above are some specific implementations of a fault detection and split-channel re-encoding method for dual-channel recording in a dynamic audio environment provided by embodiments of this application. Based on this, this application also provides a corresponding device. The device provided by the embodiments of this application will be described below from the perspective of functional modularity.
[0063] Figure 2 This is a schematic diagram of a fault detection and branch-path reconstruction system for dual-channel recording in a dynamic audio environment, provided as an embodiment of this application. (Combined with...) Figure 2 As shown in the embodiment of this application, the fault detection and branch reconstruction system 200 for dual-channel recording in a dynamic audio environment includes: The acquisition and processing unit 210 is used to obtain a first audio data through a first acquisition interface and a second audio data through a second acquisition interface, convert the first audio data and the second audio data into a unified target format and send them into the same audio writing pipeline. The detection unit 220 is used to acquire fault detection information, which includes at least two of the following: audio device events, acquisition session status, device identifier polling results, branch frame arrival status, and local frame energy status of the acquisition component. The classification unit 230 is used to determine the path to which the anomaly belongs based on the fault detection information, wherein the path is a first audio path or a second audio path; The isolation and cleanup unit 240 is used to keep the non-abnormal path and the audio writing pipeline running, stop the abnormal path, and clean up the buffer state, format conversion state and playback scheduling state of the abnormal path. The reconstruction unit 250 is used to reconstruct the abnormal path according to the current audio device status and restore the data callback of the reconstructed abnormal path. The confirmation unit 260 is used to confirm that the reconstruction was successful after detecting that a new audio frame was generated in the reconstructed abnormal path. The retry control unit 270 is used to accumulate the number of retries when reconstruction fails, and output an error status after the number of retries reaches a preset upper limit.
[0064] In one implementation of this application embodiment, the detection unit acquires various types of fault detection information, including: When acquiring the audio device event, receive the default output device change event; When obtaining the acquisition session status, receive acquisition session interruption event, interruption end event, or runtime error event; When obtaining the device identifier polling result, the current input device identifier and the current output device identifier are compared with the recorded baseline identifier at a preset period. When obtaining the arrival status of the split frame, the timestamps of the most recent positive frame data received by the first audio path and the second audio path are recorded respectively. When acquiring the local frame energy state of the acquisition component, the cumulative frame progress and average energy of the process audio capture unit are detected according to a preset period.
[0065] In one implementation of this application, the isolation and cleanup unit cleans up the buffer state, format conversion state, and playback scheduling state of the abnormal path, including: When the abnormal path is a system audio path based on the process audio interception unit, clear the cumulative buffer, resampler buffer and player queue of the system audio path, and set the fade-in state after reconstruction. When the abnormal path is a microphone path based on an independent audio acquisition session, stop the acquisition session of the microphone path, remove the session observer, clear the acquisition object and the accumulated buffer, and reacquire the default input device after a preset device stabilization time.
[0066] In one implementation of this application, the system further includes: The sampling rate protection unit is used to clear the cumulative buffer and format conversion cache of the corresponding path when it detects a change in the input sampling rate of the first audio data or the second audio data, and to resample the subsequent audio data to the unified target format.
[0067] In one implementation of this application, the system further includes: The file verification unit is used to read the media duration of the output audio after recording stops, and to calculate and estimate the duration based on the cumulative number of written frames and the target sampling rate when the media duration reading fails or the media duration is not positive.
[0068] In one implementation of this application, the reconstruction unit re-establishes the abnormal path based on the current audio device state, including: After the device status stabilizes, the corresponding path acquisition is re-established based on the current default audio device.
[0069] In one implementation of this application, the confirmation unit detects that the reconstructed abnormal path generates a new audio frame, including: After the data callback of the reconstructed abnormal path is received, it is monitored whether the data callback of the path receives a new audio frame. The arrival of the new audio frame is used as a confirmation sign that the abnormal path reconstruction is successful.
[0070] This application also provides corresponding devices and computer storage media for implementing the solutions provided in this application.
[0071] The device includes a memory and a processor. The memory stores instructions or code, and the processor executes the instructions or code to cause the device to perform the method described in any embodiment of this application.
[0072] The computer storage medium stores code, and when the code is run, the device running the code implements the method described in any embodiment of this application.
[0073] As can be seen from the above description of the embodiments, those skilled in the art can clearly understand that all or part of the steps in the methods of the above embodiments can be implemented by means of software plus a general-purpose hardware platform. Based on this understanding, the technical solution of this application can be embodied in the form of a software product. This computer software product can be stored in a storage medium, such as a read-only memory (ROM) / RAM, magnetic disk, optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, a server, or a network communication device such as a router) to execute the methods described in various embodiments or some parts of the embodiments of this application.
[0074] It is understood that in the specific embodiments of this application, the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved need to obtain user permission or consent when the above embodiments of this application are applied to specific products or technologies, and the collection, use and processing of related data need to comply with the relevant laws, regulations and standards of relevant countries and regions.
[0075] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0076] It should also be noted that the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for the device and system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiments. The device and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components indicated as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of the solution in this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0077] The above description is merely one specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for fault detection and branch-channel reconstruction in dual-channel recording under dynamic audio conditions, characterized in that, The method includes: The first audio data is obtained through the first acquisition interface, and the second audio data is obtained through the second acquisition interface. The first audio data and the second audio data are converted into a unified target format and sent into the same audio writing pipeline. Acquire fault detection information, which includes at least two of the following: audio device events, acquisition session status, device identifier polling results, split frame arrival status, and local frame energy status of the acquisition component. The path to which the anomaly belongs is determined based on the fault detection information, and the path is either the first audio path or the second audio path; Keep the non-abnormal path and the audio write pipeline running, stop the abnormal path, and clear the buffer state, format conversion state and playback scheduling state of the abnormal path. The abnormal path is re-established according to the current audio device status, the data callback of the reconstructed abnormal path is restored, and the reconstruction is confirmed to be successful after a new audio frame is detected in the reconstructed abnormal path. When reconstruction fails, the number of retries is accumulated, and an error status is output after the number of retries reaches a preset upper limit.
2. The method according to claim 1, characterized in that, The acquisition of fault detection information includes: When acquiring the audio device event, receive the default output device change event; When obtaining the acquisition session status, receive acquisition session interruption event, interruption end event, or runtime error event; When obtaining the device identifier polling result, the current input device identifier and the current output device identifier are compared with the recorded baseline identifier at a preset period. When obtaining the arrival status of the split frame, the timestamps of the most recent positive frame data received by the first audio path and the second audio path are recorded respectively. When acquiring the local frame energy state of the acquisition component, the cumulative frame progress and average energy of the process audio capture unit are detected according to a preset period.
3. The method according to claim 1, characterized in that, The process of clearing the buffer state, format conversion state, and playback scheduling state of the abnormal path includes: When the abnormal path is a system audio path based on the process audio interception unit, clear the cumulative buffer, resampler buffer and player queue of the system audio path, and set the fade-in state after reconstruction. When the abnormal path is a microphone path based on an independent audio acquisition session, stop the acquisition session of the microphone path, remove the session observer, clear the acquisition object and the accumulated buffer, and reacquire the default input device after a preset device stabilization time.
4. The method according to claim 1, characterized in that, The method further includes: When a change in the input sampling rate of the first or second audio data is detected, the cumulative buffer and format conversion cache of the corresponding path are cleared, and subsequent audio data is resampled to the unified target format.
5. The method according to claim 1, characterized in that, The method further includes: After recording stops, read the duration of the output audio media; If the media duration reading fails or the media duration is not positive, the estimated duration is calculated based on the cumulative number of written frames and the target sampling rate.
6. The method according to claim 1, characterized in that, The step of re-establishing the abnormal path based on the current audio device status includes: After the device status stabilizes, the corresponding path acquisition is re-established based on the current default audio device.
7. The method according to claim 1, characterized in that, The detection of new audio frames generated by the reconstructed abnormal path includes: After the data callback of the reconstructed abnormal path is received, it is monitored whether the data callback of the path receives a new audio frame. The arrival of the new audio frame is used as a confirmation sign that the abnormal path reconstruction is successful.
8. A fault detection and branch-channel reconstruction device for dual-channel recording in a dynamic audio environment, characterized in that, The system includes: The acquisition and processing unit is used to obtain a first audio data channel through a first acquisition interface and a second audio data channel through a second acquisition interface, convert the first audio data channel and the second audio data channel into a unified target format and send them into the same audio writing pipeline. The detection unit is used to acquire fault detection information, which includes at least two of the following: audio device events, acquisition session status, device identifier polling results, multi-path frame arrival status, and local frame energy status of the acquisition component. A classification unit is used to determine the path to which the anomaly belongs based on the fault detection information, wherein the path is a first audio path or a second audio path; The isolation and cleanup unit is used to keep the non-abnormal path and the audio writing pipeline running, stop the abnormal path, and clean up the buffer state, format conversion state and playback scheduling state of the abnormal path. The reconstruction unit is used to reconstruct the abnormal path according to the current audio device status and restore the data callback of the reconstructed abnormal path. The confirmation unit is used to confirm that the reconstruction was successful after detecting that a new audio frame was generated in the reconstructed abnormal path. The retry control unit is used to accumulate the number of retries when reconstruction fails, and output an error status after the number of retries reaches a preset upper limit.
9. A computing device, characterized in that, The computing device includes: a memory and a processor; The memory is used to store computer programs; The processor is configured to implement the steps of the method as described in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method as described in any one of claims 1 to 7.
