Audio file analysis method and device

By reading and parsing audio files in blocks by preset time slices, the problems of low efficiency and poor accuracy of audio files are solved, and the rational utilization of system resources and efficient and accurate analysis of audio files are achieved.

CN119229880AInactive Publication Date: 2024-12-31GUANGZHOU BAOLUN ELECTRONICS CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411333278.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-24
Publication Date
2024-12-31
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Existing audio file parsing methods are prone to occupying system resources for a long time when processing large audio files, resulting in inefficiency and difficult multi-threaded parallel processing, which can easily cause audio files to be damaged and affect the parsing accuracy.

Method used

Use preset time slices to read and parse audio files in chunks. By limiting the reading and parsing time within each time slice, it ensures the rational use of system resources, and dynamically adjusts read priority through system load and CPU occupancy. to avoid long-term blocking and file corruption.

Benefits of technology

It improves the efficiency and accuracy of audio file parsing, reduces system resource usage, and ensures the accurate calculation and parsing efficiency of audio file.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119229880A_ABST
    Figure CN119229880A_ABST
Patent Text Reader

Abstract

The invention discloses an audio file analysis method and device, and the method comprises the steps: obtaining an audio file, and carrying out the block reading of the audio file through a plurality of preset time slices, and obtaining a plurality of audio data blocks; analyzing the audio data block in each time slice to obtain corresponding audio information, and obtaining audio duration based on the audio information; and accumulating the audio durations corresponding to the time slices to obtain a total audio duration corresponding to the audio file. According to the invention, the occupation of system resources can be reduced, and the audio file analysis efficiency and accuracy are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of audio analysis, and in particular to an audio file analysis method and device. Background Art

[0002] Audio analysis is a basic and important technology in the field of audio processing. It plays a key role in the analysis, editing, recognition, management, compression, repair, visualization and cross-platform compatibility of audio content.

[0003] Currently, audio files are generally parsed through blocking scanning methods and multi-threaded parallel reading methods, but these parsing methods have limitations. Among them, traditional blocking methods will occupy system resources for a long time when processing large audio files, resulting in other operations being unable to be performed, thereby affecting efficiency; and multi-threaded parallel processing methods are difficult to implement and can easily cause audio file damage, thereby affecting parsing accuracy.

[0004] Application Contents

[0005] The present application provides an audio file parsing method and device to reduce the occupation of system resources and improve the efficiency and accuracy of audio file parsing.

[0006] In a first aspect, the present application provides an audio file parsing method, comprising:

[0007] Acquire an audio file, and read the audio file in blocks according to a number of preset time slices to obtain a number of audio data blocks;

[0008] Parsing the audio data block in each time slice to obtain corresponding audio information, and obtaining the audio duration based on the audio information;

[0009] The audio durations corresponding to the time slices are accumulated to obtain the total audio duration corresponding to the audio file.

[0010] The embodiment of the present application presets time slices and reads the audio file in blocks based on the time slices, so that the reading process of the audio file can be converted into a scanning process of several small time slices, and a fixed-size audio data block can be scanned according to the preset time slice, ensuring that the reading process will not occupy system resources for a long time, avoiding the situation of long-term blocking of the program. In addition, by reading in blocks, memory usage is reduced, the efficiency of audio file parsing is improved, and subsequent parsing of each audio data block is convenient; by parsing the audio data block scanned out of each time slice and limiting the parsing time in each time slice, the audio information in the corresponding audio data block in each time slice can be accurately parsed, the audio file parsing has high accuracy and audio parsing efficiency, and the audio duration is obtained based on the audio information, which is convenient for the subsequent calculation of the total duration of the audio file; by accumulating the audio duration corresponding to each time slice, the total audio duration corresponding to the audio file can be quickly obtained, which can reduce the occupation of system resources and improve the efficiency and accuracy of audio file parsing.

[0011] Furthermore, the audio file is read in blocks through a plurality of preset time slices to obtain a plurality of audio data blocks, specifically:

[0012] Preset the time slice for reading audio files according to the system load and the size of the audio files;

[0013] Data is read block by block from the audio file according to a preset data size in a time slice order or a reading priority to obtain a plurality of audio data blocks, wherein the reading priority is determined by a system load or a CPU occupancy rate.

[0014] In this way, by limiting the execution time of the read operation within each time slice, reading in the order of the time slice can ensure that each task has a chance to be executed, and reading according to the read priority can ensure that the impact of the scanning task on other key tasks is reduced when system resources are tight.

[0015] Furthermore, before obtaining the plurality of audio data blocks, the method further includes:

[0016] Determine whether the system load or CPU usage meets the data reading requirements;

[0017] If the data reading requirement is not met, the reading of the audio file corresponding to the current time slice is paused or skipped.

[0018] This controls read operations based on system load or CPU usage, ensuring that long read tasks do not negatively impact system performance.

[0019] Further, the audio data block is parsed in each time slice to obtain corresponding audio information, and the audio duration is obtained based on the audio information, specifically:

[0020] Extracting information from the audio data block in each time slice to obtain corresponding audio information, wherein the audio information includes a frame length, a frame rate, and a frame size, and the frame size is determined by a preset bit rate and a sampling rate;

[0021] Based on the frame rate corresponding to each time slice, a total number of frames corresponding to each time slice is obtained;

[0022] Based on the total number of frames and the sampling rate in each time slice, the audio duration corresponding to each time slice is obtained.

[0023] In this way, by parsing the audio data blocks scanned from each time slice and limiting the parsing time in each time slice, the audio information in the corresponding audio data block in each time slice can be accurately parsed, the audio file parsing is highly accurate and the audio parsing efficiency is high.

[0024] Furthermore, after obtaining the audio duration based on the audio information, the method further includes:

[0025] Obtaining first audio duration data corresponding to the audio data block in the current time slice;

[0026] The second audio duration data obtained in the next time slice is compared with the first audio duration data. If the second audio duration data is different from the first audio duration data, the newly added or changed part of the audio duration data is transmitted.

[0027] In this way, by comparing the audio duration data read in the current time slice and the next time slice, it is possible to determine whether the duration of the read audio file has changed, and only update the data of the newly added or changed part, thereby ensuring that the same audio data block will not be read repeatedly, thereby causing errors in audio duration, thereby improving the accuracy of audio file parsing.

[0028] In a second aspect, the present application provides an audio file parsing device, including: an acquisition module, a parsing module and a calculation module;

[0029] The acquisition module is used to acquire an audio file and read the audio file in blocks according to a number of preset time slices to obtain a number of audio data blocks;

[0030] The parsing module is used to parse the audio data block in each time slice to obtain corresponding audio information, and obtain the audio duration based on the audio information;

[0031] The calculation module is used to accumulate the audio durations corresponding to each time slice to obtain a total audio duration corresponding to the audio file.

[0032] The embodiment of the present application presets time slices and reads the audio file in blocks based on the time slices, so that the reading process of the audio file can be converted into a scanning process of several small time slices, and a fixed-size audio data block can be scanned according to the preset time slice, ensuring that the reading process will not occupy system resources for a long time, avoiding the situation of long-term blocking of the program. In addition, by reading in blocks, memory usage is reduced, the efficiency of audio file parsing is improved, and subsequent parsing of each audio data block is convenient; by parsing the audio data block scanned out of each time slice and limiting the parsing time in each time slice, the audio information in the corresponding audio data block in each time slice can be accurately parsed, the audio file parsing has high accuracy and audio parsing efficiency, and the audio duration is obtained based on the audio information, which is convenient for the subsequent calculation of the total duration of the audio file; by accumulating the audio duration corresponding to each time slice, the total audio duration corresponding to the audio file can be quickly obtained, which can reduce the occupation of system resources and improve the efficiency and accuracy of audio file parsing.

[0033] Further, the acquisition module includes: a setting unit and a first acquisition unit;

[0034] The setting unit is used to pre-set the time slice for reading the audio file according to the system load and the size of the audio file;

[0035] The first acquisition unit is used to read data from the audio file block by block according to a preset data size in a time slice order or a reading priority to obtain a plurality of audio data blocks, wherein the reading priority is determined by a system load or a CPU occupancy rate.

[0036] Furthermore, the audio file parsing device further comprises a judgment module, and the judgment module comprises: a judgment unit and a processing unit;

[0037] The judging unit is used to judge whether the system load or CPU occupancy rate meets the data reading requirement;

[0038] The processing unit is used to pause or skip reading the audio file corresponding to the current time slice if the data reading requirement is not met.

[0039] Further, the parsing module includes: an extraction unit, a first calculation unit and a second calculation unit;

[0040] The extraction unit is used to extract information from the audio data block in each time slice to obtain corresponding audio information, wherein the audio information includes a frame length, a frame rate and a frame size, and the frame size is determined by a preset bit rate and a sampling rate;

[0041] The first calculation unit is used to obtain the total number of frames corresponding to each time slice based on the frame rate corresponding to each time slice;

[0042] The second calculation unit is used to obtain the audio duration corresponding to each time slice based on the total number of frames and the sampling rate in each time slice.

[0043] Furthermore, the audio file parsing device further includes: a transmission module, the transmission module including: a second acquisition unit and a comparison unit:

[0044] The second acquisition unit is used to acquire first audio duration data corresponding to the audio data block in the current time slice;

[0045] The comparing unit is used to compare the second audio duration data obtained in the next time slice with the first audio duration data, and if the second audio duration data is different from the first audio duration data, transmit the newly added or changed part in the audio duration data. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] Figure 1 It is a flowchart of an embodiment of an audio file parsing method provided by the present application;

[0047] Figure 2 It is a structural diagram of an embodiment of an audio file parsing device provided by the present application. DETAILED DESCRIPTION

[0048] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0049] It should be understood that the step numbers used in this article are only for the convenience of description and are not intended to limit the order in which the steps are executed.

[0050] It should be understood that the terms used in the present specification are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the present specification and the appended claims, the singular forms "a", "an" and "the" are intended to include plural forms unless the context clearly indicates otherwise.

[0051] The terms “include” and “comprising” indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.

[0052] The term "and / or" means and includes any and all possible combinations of one or more of the associated listed items.

[0053] Audio parsing is crucial for the analysis, editing, recognition, management, compression, repair, visualization and cross-platform compatibility of audio content. Existing parsing methods such as blocking scanning methods and multi-threaded parallel reading methods have limitations. Among them, the blocking scanning method is prone to occupying system resources for a long time, making other operations unable to be performed, thereby affecting efficiency; while the multi-threaded parallel reading method is difficult to implement and is prone to damage audio files, thereby affecting the parsing accuracy.

[0054] Embodiment 1

[0055] Please refer to Figure 1 , Figure 1 It is a flowchart of an embodiment of an audio file parsing method provided by the present application, including steps S1 to S3;

[0056] Step S1, obtaining an audio file, and reading the audio file in blocks according to a number of preset time slices to obtain a number of audio data blocks;

[0057] It is understandable that the audio file can be obtained through existing technologies, including but not limited to directly recording the audio file or receiving the audio file uploaded by the user.

[0058] After the audio file is obtained, the audio file can be read. Specifically, firstly, since the setting of the time slice is the basis of the system scheduling task, it determines the time occupied by each audio file reading operation on the system, so it is necessary to pre-set the time slice for reading the audio file according to the system load and the size of the audio file; secondly, in order to ensure that each time slice has an opportunity to execute, the audio file can be read in a round-robin scheduling manner. Of course, in order to reduce the impact of the reading task on other key figures when the system resources are tight, the audio file can also be read in a priority scheduling manner. Specifically, it can be, but not limited to, through an event loop or a scheduler, according to the time slice sequence or the reading priority, the data is read block by block according to the preset data size from the audio file to obtain a number of audio data blocks, wherein the reading priority is determined by the system load or the CPU occupancy rate, when the system load and the CPU occupancy rate change, the reading priority and the execution frequency will be dynamically adjusted, and exemplarily but not limitedly, when it is under high load, the execution frequency of non-critical tasks (such as audio reading tasks) is reduced to ensure that the system critical tasks are prioritized.

[0059] It should be noted that after the time slice is preset, each reading operation cannot exceed the preset time slice length, and the time slice can be adjusted dynamically. Specifically, the system resource utilization will be monitored in real time, including but not limited to CPU usage, memory usage, disk I / O, etc., to dynamically adjust the size of the time slice and scheduling frequency to ensure that long scanning tasks will not have a negative impact on system performance. When the system resource utilization is high, the size of the time slice can be appropriately reduced to reduce the scanning frequency; when the system resource utilization is low, the time slice can be increased to speed up the scanning task.

[0060] In this way, by limiting the execution time of the read operation within each time slice, reading in the order of the time slice can ensure that each task has a chance to be executed, and reading according to the read priority can ensure that the impact of the scanning task on other key tasks is reduced when system resources are tight.

[0061] In the process of reading the audio file, it is also necessary to determine in real time whether the system load or CPU occupancy meets the data reading requirements; if the data reading requirements are not met, the reading of the audio file corresponding to the current time slice can be paused or skipped through but not limited to an event loop or a scheduler. That is to say, when reading the audio file in the current time slice, if it is found that the system load pressure is too high, the current reading operation can be skipped and wait for the next time slice to read.

[0062] This controls read operations based on system load or CPU usage, ensuring that long read tasks do not negatively impact system performance.

[0063] When several audio data blocks are read out, they can be saved one by one in a preset buffer with a fixed size. At the end of each time slice, the total length of the audio data that has been read will be recorded in the buffer. When the current audio file length exceeds the buffer, the audio data blocks will be read repeatedly until the audio file is read. Among them, the size of the buffer is usually related to the sampling rate, bit rate and CPU processing power, and these parameters are generally set in advance. For example but not limiting, for ordinary audio files, the buffer size can be set to 4KB to 64KB. Of course, the specific size selection should take into account the balance between memory usage and I / O efficiency. Generally speaking, if it is in a low-latency application scenario, the buffer size can be set to 4KB, and in order to achieve efficient batch processing, the buffer size can be set to 64KB.

[0064] It should be noted that the format, sampling rate, bit rate, encoding method and other parameters of the audio file will be set in advance so that the reading pointer can be used to parse the audio file later. The audio format can be but not limited to MP3, WAV and AAC, the sampling rate can be but not limited to 44.1kHz and 48kHz, the bit rate can be but not limited to 128kbps and 320kbps, and the audio encoding method can be but not limited to CBR (constant bit rate) or VBR (variable bit rate). After setting these parameters in advance, the corresponding content can be parsed according to the obtained audio file header information.

[0065] It should be noted that the preset data size is fixed, and the set size depends on the size of the buffer for storing the data block. By dividing a large audio file into audio data blocks of fixed length, the memory usage can be reduced and the parallel efficiency of reading can be improved.

[0066] Step S2, parsing the audio data block in each time slice to obtain corresponding audio information, and obtaining the audio duration based on the audio information;

[0067] It is understandable that when the audio data blocks are read out from the audio file, the audio data blocks can be parsed one by one. Specifically, first, the information in the audio data blocks stored in the buffer is extracted in each time slice to obtain the corresponding audio information, wherein the audio information includes frame length, frame rate and frame size, and the frame size is determined by the preset bit rate and sampling rate; secondly, based on the corresponding frame rate in each time slice, the corresponding total number of frames in each time slice is obtained; finally, based on the total number of frames in each time slice and the sampling rate, the corresponding audio duration in each time slice is obtained, that is, audio duration = total number of frames / sampling rate.

[0068] It should be noted that the frame length is the length (number of bytes) of each audio frame, the frame rate is the audio samples contained per second, and the frame size is the amount of data corresponding to each frame, which is determined by the bit rate and sampling rate, and the bit rate and sampling rate have been set in advance when parsing the audio data block.

[0069] In this way, by parsing the audio data blocks scanned from each time slice and limiting the parsing time in each time slice, the audio information in the corresponding audio data block in each time slice can be accurately parsed, the audio file parsing is highly accurate and the audio parsing efficiency is high.

[0070] After obtaining the audio duration corresponding to a time slice, in order to prevent repeated parsing of an audio data block, it is necessary to compare the difference between the audio duration data corresponding to the current time slice and the next time slice. Specifically, at each time analysis, the first audio duration data corresponding to the audio data block in the current time slice is calculated, and the second audio duration data obtained in the next time slice is compared with the first audio duration data. If the second audio duration data is different from the first audio duration data, it means that there is a need to transmit the duration data, and the newly added or changed part of the audio duration data is transmitted. Among them, when calculating the first audio duration data corresponding to the audio data block in the current time slice, a snapshot can be retained, and the snapshot can be used to determine whether the audio duration data has changed later.

[0071] In this way, by comparing the audio duration data read in the current time slice and the next time slice, it is possible to determine whether the duration of the read audio file has changed, and only update the data of the newly added or changed part, thereby ensuring that the same audio data block will not be read repeatedly, thereby causing errors in audio duration, thereby improving the accuracy of audio file parsing.

[0072] Step S3: Accumulate the audio durations corresponding to the time slices to obtain the total audio duration corresponding to the audio file.

[0073] It is understandable that after obtaining the audio duration corresponding to each time slice, all audio durations corresponding to the time slices may be accumulated to obtain the total audio duration corresponding to the audio file.

[0074] It should be noted that when parsing the audio duration, in order not to block the main thread's processing, asynchronous processing technology will be used, that is, the file reading and duration calculation operations are separated during the reading process. Therefore, each time the reading operation is called, the main thread, that is, reading the file, will not be blocked, but will continue to implement coordination and task scheduling and other operations. The duration calculation task will be placed in other independent threads, thus avoiding long-term blocking of the program.

[0075] The embodiment of the present application presets time slices and reads the audio file in blocks based on the time slices, so that the reading process of the audio file can be converted into a scanning process of several small time slices, and a fixed-size audio data block can be scanned according to the preset time slice, ensuring that the reading process will not occupy system resources for a long time, avoiding the situation of long-term blocking of the program. In addition, by reading in blocks, memory usage is reduced, the efficiency of audio file parsing is improved, and subsequent parsing of each audio data block is convenient; by parsing the audio data block scanned out of each time slice and limiting the parsing time in each time slice, the audio information in the corresponding audio data block in each time slice can be accurately parsed, the audio file parsing has high accuracy and audio parsing efficiency, and the audio duration is obtained based on the audio information, which is convenient for the subsequent calculation of the total duration of the audio file; by accumulating the audio duration corresponding to each time slice, the total audio duration corresponding to the audio file can be quickly obtained, which can reduce the occupation of system resources and improve the efficiency and accuracy of audio file parsing.

[0076] Embodiment 2

[0077] Please refer to Figure 2 , Figure 2 It is a structural diagram of an embodiment of an audio file parsing device provided by the present application, comprising an acquisition module 01, a parsing module 02 and a calculation module 03;

[0078] The acquisition module 01 is used to acquire an audio file and read the audio file in blocks according to a number of preset time slices to obtain a number of audio data blocks;

[0079] It is understandable that the audio file can be obtained through existing technologies, including but not limited to directly recording the audio file or receiving the audio file uploaded by the user.

[0080] The acquisition module 01 includes: a setting unit and a first acquisition unit; the setting unit is used to pre-set a time slice for reading an audio file according to a system load and a size of the audio file; the first acquisition unit is used to read data from the audio file block by block according to a preset data size in a time slice order or a reading priority to obtain a plurality of audio data blocks, wherein the reading priority is determined by the system load or the CPU occupancy rate.

[0081] After the audio file is obtained, the audio file can be read. Specifically, firstly, since the setting of the time slice is the basis of the system scheduling task, it determines the time occupied by each audio file reading operation on the system, so it is necessary to pre-set the time slice for reading the audio file according to the system load and the size of the audio file; secondly, in order to ensure that each time slice has an opportunity to execute, the audio file can be read in a round-robin scheduling manner. Of course, in order to reduce the impact of the reading task on other key figures when the system resources are tight, the audio file can also be read in a priority scheduling manner. Specifically, it can be, but not limited to, through an event loop or a scheduler, according to the time slice sequence or the reading priority, the data is read block by block according to the preset data size from the audio file to obtain a number of audio data blocks, wherein the reading priority is determined by the system load or the CPU occupancy rate, when the system load and the CPU occupancy rate change, the reading priority and the execution frequency will be dynamically adjusted, and exemplarily but not limitedly, when it is under high load, the execution frequency of non-critical tasks (such as audio reading tasks) is reduced to ensure that the system critical tasks are prioritized.

[0082] It should be noted that after the time slice is preset, each reading operation cannot exceed the preset time slice length, and the time slice can be adjusted dynamically. Specifically, the system resource utilization will be monitored in real time, including but not limited to CPU usage, memory usage, disk I / O, etc., to dynamically adjust the size of the time slice and scheduling frequency to ensure that long scanning tasks will not have a negative impact on system performance. When the system resource utilization is high, the size of the time slice can be appropriately reduced to reduce the scanning frequency; when the system resource utilization is low, the time slice can be increased to speed up the scanning task.

[0083] In this way, by limiting the execution time of the read operation within each time slice, reading in the order of the time slice can ensure that each task has a chance to be executed, and reading according to the read priority can ensure that the impact of the scanning task on other key tasks is reduced when system resources are tight.

[0084] The audio file parsing device also includes a judgment module, which includes: a judgment unit and a processing unit; the judgment unit is used to judge whether the system load or CPU occupancy meets the data reading requirements; the processing unit is used to pause or skip reading the audio file corresponding to the current time slice if the data reading requirements are not met.

[0085] In the process of reading the audio file, it is also necessary to determine in real time whether the system load or CPU occupancy meets the data reading requirements; if the data reading requirements are not met, the reading of the audio file corresponding to the current time slice can be paused or skipped through but not limited to an event loop or a scheduler. That is to say, when reading the audio file in the current time slice, if it is found that the system load pressure is too high, the current reading operation can be skipped and wait for the next time slice to read.

[0086] This controls read operations based on system load or CPU usage, ensuring that long read tasks do not negatively impact system performance.

[0087] When several audio data blocks are read out, they can be saved one by one in a preset buffer with a fixed size. At the end of each time slice, the total length of the audio data that has been read will be recorded in the buffer. When the current audio file length exceeds the buffer, the audio data blocks will be read repeatedly until the audio file is read. Among them, the size of the buffer is usually related to the sampling rate, bit rate and CPU processing power, and these parameters are generally set in advance. For example but not limiting, for ordinary audio files, the buffer size can be set to 4KB to 64KB. Of course, the specific size selection should take into account the balance between memory usage and I / O efficiency. Generally speaking, if it is in a low-latency application scenario, the buffer size can be set to 4KB, and in order to achieve efficient batch processing, the buffer size can be set to 64KB.

[0088] It should be noted that the format, sampling rate, bit rate, encoding method and other parameters of the audio file will be set in advance so that the reading pointer can be used to parse the audio file later. The audio format can be but not limited to MP3, WAV and AAC, the sampling rate can be but not limited to 44.1kHz and 48kHz, the bit rate can be but not limited to 128kbps and 320kbps, and the audio encoding method can be but not limited to CBR (constant bit rate) or VBR (variable bit rate). After setting these parameters in advance, the corresponding content can be parsed according to the obtained audio file header information.

[0089] It should be noted that the preset data size is fixed, and the set size depends on the size of the buffer for storing the data block. By dividing a large audio file into audio data blocks of fixed length, the memory usage can be reduced and the parallel efficiency of reading can be improved.

[0090] The analysis module 02 is used to analyze the audio data block in each time slice to obtain corresponding audio information, and obtain the audio duration based on the audio information;

[0091] The parsing module 02 includes: an extraction unit, a first calculation unit and a second calculation unit; the extraction unit is used to extract the information in the audio data block in each time slice to obtain the corresponding audio information, wherein the audio information includes a frame length, a frame rate and a frame size, and the frame size is determined by a preset bit rate and a sampling rate; the first calculation unit is used to obtain the corresponding total number of frames in each time slice based on the corresponding frame rate in each time slice; the second calculation unit is used to obtain the corresponding audio duration in each time slice based on the total number of frames in each time slice and the sampling rate.

[0092] It is understandable that when the audio data blocks are read out from the audio file, the audio data blocks can be parsed one by one. Specifically, first, the information in the audio data blocks stored in the buffer is extracted in each time slice to obtain the corresponding audio information, wherein the audio information includes frame length, frame rate and frame size, and the frame size is determined by the preset bit rate and sampling rate; secondly, based on the corresponding frame rate in each time slice, the corresponding total number of frames in each time slice is obtained; finally, based on the total number of frames in each time slice and the sampling rate, the corresponding audio duration in each time slice is obtained, that is, audio duration = total number of frames / sampling rate.

[0093] It should be noted that the frame length is the length (number of bytes) of each audio frame, the frame rate is the audio samples contained per second, and the frame size is the amount of data corresponding to each frame, which is determined by the bit rate and sampling rate, and the bit rate and sampling rate have been set in advance when parsing the audio data block.

[0094] In this way, by parsing the audio data blocks scanned from each time slice and limiting the parsing time in each time slice, the audio information in the corresponding audio data block in each time slice can be accurately parsed, the audio file parsing is highly accurate and the audio parsing efficiency is high.

[0095] The audio file parsing device also includes: a transmission module, which includes: a second acquisition unit and a comparison unit: the second acquisition unit is used to obtain the first audio duration data corresponding to the audio data block in the current time slice; the comparison unit is used to compare the second audio duration data obtained in the next time slice with the first audio duration data, and if the second audio duration data is different from the first audio duration data, then the newly added or changed part of the audio duration data is transmitted.

[0096] After obtaining the audio duration corresponding to a time slice, in order to prevent repeated parsing of an audio data block, it is necessary to compare the difference between the audio duration data corresponding to the current time slice and the next time slice. Specifically, at each time analysis, the first audio duration data corresponding to the audio data block in the current time slice is calculated, and the second audio duration data obtained in the next time slice is compared with the first audio duration data. If the second audio duration data is different from the first audio duration data, it means that there is a need to transmit the duration data, and the newly added or changed part of the audio duration data is transmitted. Among them, when calculating the first audio duration data corresponding to the audio data block in the current time slice, a snapshot can be retained, and the snapshot can be used to determine whether the audio duration data has changed later.

[0097] In this way, by comparing the audio duration data read in the current time slice and the next time slice, it is possible to determine whether the duration of the read audio file has changed, and only update the data of the newly added or changed part, thereby ensuring that the same audio data block will not be read repeatedly, thereby causing errors in audio duration, thereby improving the accuracy of audio file parsing.

[0098] The calculation module 03 is used to accumulate the audio durations corresponding to the time slices to obtain the total audio duration corresponding to the audio file.

[0099] It is understandable that after obtaining the audio duration corresponding to each time slice, all audio durations corresponding to the time slices may be accumulated to obtain the total audio duration corresponding to the audio file.

[0100] It should be noted that when parsing the audio duration, in order not to block the main thread's processing, asynchronous processing technology will be used, that is, the file reading and duration calculation operations are separated during the reading process. Therefore, each time the reading operation is called, the main thread, that is, reading the file, will not be blocked, but will continue to implement coordination and task scheduling and other operations. The duration calculation task will be placed in other independent threads, thus avoiding long-term blocking of the program.

[0101] The embodiment of the present application presets time slices and reads the audio file in blocks based on the time slices, so that the reading process of the audio file can be converted into a scanning process of several small time slices, and a fixed-size audio data block can be scanned according to the preset time slice, ensuring that the reading process will not occupy system resources for a long time, avoiding the situation of long-term blocking of the program. In addition, by reading in blocks, memory usage is reduced, the efficiency of audio file parsing is improved, and subsequent parsing of each audio data block is convenient; by parsing the audio data block scanned out of each time slice and limiting the parsing time in each time slice, the audio information in the corresponding audio data block in each time slice can be accurately parsed, the audio file parsing has high accuracy and audio parsing efficiency, and the audio duration is obtained based on the audio information, which is convenient for the subsequent calculation of the total duration of the audio file; by accumulating the audio duration corresponding to each time slice, the total audio duration corresponding to the audio file can be quickly obtained, which can reduce the occupation of system resources and improve the efficiency and accuracy of audio file parsing.

[0102] The specific embodiments described above further describe the purpose, technical solutions and beneficial effects of the present application in detail. It should be understood that the above description is only a specific embodiment of the present application and is not intended to limit the scope of protection of the present application. It is particularly pointed out that for those skilled in the art, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of protection of the present application.

Claims

1. A method for parsing an audio file, characterized in that: include: Acquire an audio file, and read the audio file in blocks according to a number of preset time slices to obtain a number of audio data blocks; Parsing the audio data block in each time slice to obtain corresponding audio information, and obtaining the audio duration based on the audio information; The audio durations corresponding to the time slices are accumulated to obtain the total audio duration corresponding to the audio file.

2. The audio file parsing method according to claim 1, characterized in that: The audio file is read in blocks by using a plurality of preset time slices to obtain a plurality of audio data blocks, specifically: Preset the time slice for reading audio files according to the system load and the size of the audio files; Data is read block by block from the audio file according to a preset data size in a time slice order or a reading priority to obtain a plurality of audio data blocks, wherein the reading priority is determined by a system load or a CPU occupancy rate.

3. The audio file parsing method according to any one of claims 1 to 2, characterized in that: Before obtaining the plurality of audio data blocks, the method further includes: Determine whether the system load or CPU usage meets the data reading requirements; If the data reading requirement is not met, the reading of the audio file corresponding to the current time slice is paused or skipped.

4. The audio file parsing method according to claim 1, characterized in that: The audio data block is parsed in each time slice to obtain corresponding audio information, and the audio duration is obtained based on the audio information, specifically: Extracting information from the audio data block in each time slice to obtain corresponding audio information, wherein the audio information includes a frame length, a frame rate, and a frame size, and the frame size is determined by a preset bit rate and a sampling rate; Based on the frame rate corresponding to each time slice, a total number of frames corresponding to each time slice is obtained; Based on the total number of frames and the sampling rate in each time slice, the audio duration corresponding to each time slice is obtained.

5. The audio file parsing method according to claim 1, characterized in that: After obtaining the audio duration based on the audio information, the method further includes: Obtaining first audio duration data corresponding to the audio data block in the current time slice; The second audio duration data obtained in the next time slice is compared with the first audio duration data. If the second audio duration data is different from the first audio duration data, the newly added or changed part of the audio duration data is transmitted.

6. An audio file parsing device, characterized in that: include: Acquisition module, parsing module and calculation module; The acquisition module is used to acquire an audio file and read the audio file in blocks according to a number of preset time slices to obtain a number of audio data blocks; The parsing module is used to parse the audio data block in each time slice to obtain corresponding audio information, and obtain the audio duration based on the audio information; The calculation module is used to accumulate the audio durations corresponding to each time slice to obtain a total audio duration corresponding to the audio file.

7. The audio file parsing device according to claim 6, characterized in that: The acquisition module includes: a setting unit and a first acquisition unit; The setting unit is used to pre-set the time slice for reading the audio file according to the system load and the size of the audio file; The first acquisition unit is used to read data from the audio file block by block according to a preset data size in a time slice order or a reading priority to obtain a plurality of audio data blocks, wherein the reading priority is determined by a system load or a CPU occupancy rate.

8. The audio file parsing device according to any one of claims 6 to 7, characterized in that: It also includes a judgment module, which includes: a judgment unit and a processing unit; The judging unit is used to judge whether the system load or CPU occupancy rate meets the data reading requirement; The processing unit is used to pause or skip reading the audio file corresponding to the current time slice if the data reading requirement is not met.

9. The audio file parsing device according to claim 6, characterized in that: The parsing module includes: an extraction unit, a first calculation unit and a second calculation unit; The extraction unit is used to extract information from the audio data block in each time slice to obtain corresponding audio information, wherein the audio information includes a frame length, a frame rate and a frame size, and the frame size is determined by a preset bit rate and a sampling rate; The first calculation unit is used to obtain the total number of frames corresponding to each time slice based on the frame rate corresponding to each time slice; The second calculation unit is used to obtain the audio duration corresponding to each time slice based on the total number of frames and the sampling rate in each time slice.

10. The audio file parsing device according to claim 6, characterized in that: Also includes: The transmission module includes: a second acquisition unit and a comparison unit: The second acquisition unit is used to acquire first audio duration data corresponding to the audio data block in the current time slice; The comparing unit is used to compare the second audio duration data obtained in the next time slice with the first audio duration data, and if the second audio duration data is different from the first audio duration data, transmit the newly added or changed part in the audio duration data.