Voiceprint data processing method and device based on queue and electronic equipment
By using a shared queue in voiceprint recognition technology to manage voiceprint file identification, the problems of multi-process write conflicts and write imbalance are solved, and efficient and balanced voiceprint file writing is achieved.
Patent Information
- Application Number
- CN202510377590.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-28
- Publication Date
- 2025-06-13
- Estimated Expiration
- 2045-03-28
AI Technical Summary
In voiceprint recognition technology, writing the same voiceprint file at the same time by multiple processes is likely to cause data conflicts, and it is difficult to ensure the balance of voiceprint file writing.
Create and maintain a shared queue that is first-in, first-out and blocking to store voiceprint file identifiers. The voiceprint data writing process opens the voiceprint file in append write mode in the initialization stage and caches the file handle to connect to the shared queue. When there is a need for writing, the process obtains the file ID from the shared queue and uses the ID to write to the corresponding voiceprint file. After writing is completed, put the file ID back into the shared queue.
This method avoids write conflicts caused by multiple processes writing to the same voiceprint file at the same time, and ensures the balance and efficiency of voiceprint file writing through first-in-first-out order file identification management.
Smart Images

Figure CN120148522A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular, to a method, apparatus, and electronic device for processing voiceprint data based on a queue. Background Art
[0002] Voiceprint recognition technology is a type of biometric recognition technology that converts sound signals into electrical signals and uses a computer for recognition. When performing voiceprint recognition, generally, the voiceprint data extracted from an audio file is compared and authenticated with a stored voiceprint model to achieve the function of voiceprint recognition.
[0003] In related technologies, a voiceprint extraction program can extract voiceprint data using multiple processes. The voiceprint extraction processes are usually Python processes. Since Python threads cannot fully utilize computing resources, multiple processes are required. Each process continuously processes voiceprint extraction requests and saves the extracted results to one of multiple voiceprint files. However, multiple processes writing to the same voiceprint file simultaneously easily leads to data conflicts, and there may be some voiceprint files that are frequently written, while other voiceprint files are not written for a long time. Therefore, it is also difficult to ensure the balance of writing to voiceprint files.
[0004] Therefore, how to avoid writing conflicts caused by multiple threads writing to the same voiceprint file simultaneously and ensure the balance of writing to voiceprint files is a technical problem that needs to be solved urgently. Summary of the Invention
[0005] In view of this, embodiments of the present invention provide a method, apparatus, and electronic device for processing voiceprint data based on a queue to avoid writing conflicts caused by multiple threads writing to the same voiceprint file simultaneously, and ensure the balance and efficiency of writing to voiceprint files.
[0006] The technical solution of the present invention is implemented as follows: In a first aspect, a method for processing voiceprint data based on a queue is provided. The method includes: Create and maintain a shared queue, where the shared queue is a first-in-first-out and blocking-capable queue for storing a queue of voiceprint file identifiers; In the initialization stage, a voiceprint data writing process opens the voiceprint file to which the voiceprint data to be written is to be written in an append-write mode at one time and caches the handle of the voiceprint file, and connects to the shared queue; When there is a writing requirement, the voiceprint data writing process obtains a first file identifier from the shared queue, and writes the first voiceprint data corresponding to the writing requirement to the first file using the handle of the first file represented by the first file identifier; After the first voiceprint data is written, the first file identifier is put back into the shared queue.
[0007] In a second aspect, a voiceprint data processing device based on a queue is provided, which is applied to a system with a voiceprint data writing function, and includes: A queue management module, configured to create and maintain a shared queue, where the shared queue is a first-in-first-out and blocking-capable queue for storing a voiceprint file identifier queue; A process initialization module, configured to open a voiceprint file to be written with voiceprint data in an append-write mode at one time and cache a handle of the voiceprint file during the initialization phase of a voiceprint data writing process, and connect to the shared queue; In a third aspect, an electronic device is provided, including: a processor and a memory, where the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the voiceprint data processing method based on a queue provided in any one of the above embodiments.
[0008] The technical solution provided by the embodiments of the present invention has at least the following beneficial effects: Since any voiceprint data writing process obtains a first file identifier from the shared queue in a first-in-first-out order when writing voiceprint data, writing conflicts caused by multiple processes writing to the same voiceprint file can be avoided. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments and descriptions thereof are used to explain the present application and do not constitute an improper limitation of the present application. In the drawings: Figure 1 is a schematic flowchart of a voiceprint data processing method based on a queue provided by an embodiment of the present invention; Figure 2 is a schematic structural diagram of a voiceprint data writing device provided by an embodiment of the present invention; Figure 3 is a schematic structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0010] In order to enable those skilled in the art to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0011] It should be noted that the terms "first", "second", etc. in the description, claims and the above-mentioned drawings of the present invention are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of the present invention described here can be implemented in an order other than those illustrated or described here. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0012] It should also be noted that the information and data collected by the present invention (such as voiceprint data) are information and data authorized by the user or fully authorized by all parties. Moreover, the processing of relevant data, such as collection, storage, use, processing, transmission, provision, disclosure and application, complies with the relevant laws, regulations and standards of the relevant regions, takes necessary confidentiality measures, does not violate public order and good customs, and provides corresponding operation entrances for users to choose to authorize or refuse. For example, an interface is set between the present system and relevant users or institutions. Before obtaining relevant information, a request for acquisition needs to be sent to the aforementioned users or institutions through the interface, and relevant information can be obtained after receiving the consent information feedback from the aforementioned users or institutions.
[0013] In related technologies, a voiceprint extraction program can use multiple processes to extract voiceprint data, and the voiceprint extraction process is usually a Python process. In Python, due to the existence of the Global Interpreter Lock (GIL for short), the standard threads in Python cannot truly utilize the computing resources of multi-core CPUs in parallel when performing computationally intensive tasks. This is because the GIL restricts that only one thread can execute Python bytecode at the same time. Therefore, for computationally intensive tasks such as voiceprint extraction, using multiple threads cannot significantly improve performance. On the contrary, using multiple processes can bypass the limitation of the GIL because each process has its own Python interpreter and memory space, and these processes can execute computational tasks in parallel, thus making full use of the computing resources of multi-core CPUs. However, multiple processes writing to the same voiceprint file at the same time easily leads to data conflicts, and there may be some voiceprint files being written frequently while other voiceprint files are not written for a long time. Therefore, it is also difficult to ensure the balance of writing to voiceprint files.
[0014] According to an embodiment of the present invention, an embodiment of a method for processing voiceprint data based on a queue is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.
[0015] It should be noted that a voiceprint data writing device can be the execution subject of the method for processing voiceprint data based on a queue in an embodiment of the present invention. The voiceprint data writing device can be deployed on an electronic device with voiceprint data processing capabilities, and the electronic device can be an electronic device in a voiceprint recognition system, or a server, etc.
[0016] The method for processing voiceprint data based on a queue provided by the embodiment of the present invention can be applied to scenarios such as identity authentication based on voiceprint recognition, or speech recognition.
[0017] Figure 1 It is a flowchart of a method for processing voiceprint data based on a queue according to an embodiment of the present invention. Refer to Figure 1 As shown, the method for processing voiceprint data based on a queue can be used for data writing of Python threads. The method includes the following steps: Step 101: Create and maintain a shared queue, where the shared queue is a first-in-first-out and blocking-capable queue for storing a queue of voiceprint file identifiers.
[0018] The method for processing voiceprint data based on a queue provided by the embodiment of the present invention is applied to an electronic device, and the electronic device supports multiple processes, for example, supports multiple Python processes. Exemplarily, the electronic device supports a queue process and multiple voiceprint data writing processes.
[0019] According to different subjects for creating and maintaining the shared queue, step 101 may include: the thread scheduler of the operating system creates a queue process and uses the queue process to create and maintain the shared queue; or, the thread scheduler of the operating system creates and maintains the shared queue.
[0020] Exemplarily, (1) Creating and maintaining a shared queue based on a queue process. In a specific voiceprint data processing system, when the thread scheduler of the operating system starts, a dedicated queue process will be created. For example, on a voiceprint recognition server based on the Linux system, the thread scheduler creates a new process as the queue process through a system call. This queue process is assigned the task of creating and maintaining the shared queue.
[0021] The queue process utilizes the inter - process communication mechanisms provided by the system, such as shared memory and semaphores, to create a first - in - first - out (FIFO) and blocking - capable shared queue. The shared memory is used to store the voiceprint file identification queue, and the semaphore is used to ensure that the access to the shared queue is thread - safe. The queue process continuously listens for whether there are new voiceprint file identifications to be added to the queue and whether there are processes requesting to obtain the identifications in the queue. When a new voiceprint file is created, the queue process adds its identification to the shared queue; when a voiceprint data writing process requests to obtain the file identification, the queue process provides the identification according to the FIFO principle.
[0022] In some cases, the queue process is a separate process and can be referred to as the "queue process". The queue process also provides an interface for cross - process calls so that the voiceprint data writing process can access the shared queue.
[0023] (2) The operating system thread scheduler directly creates and maintains the shared queue. Assuming it is a voiceprint data acquisition device on a Windows system, the operating system's thread scheduler is directly responsible for creating and maintaining the shared queue. The thread scheduler utilizes kernel objects provided by the Windows system, such as events and critical sections, to implement the FIFO and blocking functions of the shared queue.
[0024] After creating the shared queue, the thread scheduler internally maintains a queue data structure for storing voiceprint file identifications. When the voiceprint data writing process starts and connects to the shared queue, the thread scheduler notifies the writing process of changes in the queue status through events. For example, when a new file identification is added to the shared queue, the thread scheduler triggers the corresponding event to inform the waiting writing process that it can obtain the identification; when the queue becomes empty, the thread scheduler triggers the event again to put the process attempting to obtain the identification into a blocked state until a new identification is added.
[0025] In some embodiments, the queue process or the operating system thread scheduler loads the shared queue and initializes the voiceprint files. Among them, the number of voiceprint files can be specified by the startup parameters of the process. Here, the startup parameters of the process include: the number of voiceprint files, and can also include at least one of the following: file name pattern, type of data to be written, upper limit of file size, maximum number of writes to the file, etc.
[0026] In this embodiment, the shared queue can also be referred to as the "voiceprint file queue" and is used to save the file identifications of each voiceprint file. The shared queue is a queue in the FIFO (First In First Out) manner. Each file identification is arranged in the shared queue in the order of being written, and the file identification that enters the queue earliest will be processed first.
[0027] In this embodiment, the voiceprint data writing process can be referred to as the "voiceprint extraction process". The number of voiceprint data writing processes is multiple. Multiple voiceprint data writing processes can concurrently process different audio files, generate voiceprint data, and write the voiceprint data into the voiceprint file. It can be understood that the duration required for each voiceprint data writing process to process a voice file is related to the size of the voice file, the voice complexity, and the system resources at that time.
[0028] In some examples, the voiceprint data writing process can use a voiceprint extraction algorithm (such as Mel Frequency Cepstral Coefficients MFCC) to extract voiceprint feature data from the audio file, and write the extracted voiceprint feature data into the voiceprint file in an appropriate format. Multiple voiceprint data writing processes can process multiple audio files in parallel to extract voiceprint feature data.
[0029] When the voiceprint data writing process starts, it will connect to the shared queue at the same time, so that the voiceprint data writing process can read the file identifiers written by other processes (such as the queue process) from the shared queue.
[0030] Here, there is no corresponding relationship between multiple voiceprint data writing processes and multiple voiceprint files. The number of voiceprint files can be the same as or different from the number of voiceprint data writing processes. For example, the number of voiceprint files can be more than the number of voiceprint data writing processes, or less than the number of voiceprint data writing processes.
[0031] In this embodiment, the amount of data of each voiceprint data extracted by each voiceprint data writing process is the same.
[0032] In some examples, before executing step 101, the queue process can pre-create multiple voiceprint files to be written with voiceprint data according to the number of files, and obtain the file identifiers of all voiceprint files.
[0033] Here, the file identifier can be used to uniquely identify the voiceprint file. The file identifier can be the file name or the storage path of the file. The storage path can indicate a specific storage location of each voiceprint file in the storage system. It can be understood that the file identifier can be any information that can uniquely identify the voiceprint file, and no specific limitation is made here.
[0034] In some examples, the size difference between multiple voiceprint files is less than a preset difference value. Here, the sizes of different voiceprint files are balanced, which is convenient for subsequent distribution of voiceprint recognition tasks according to the voiceprint files.
[0035] In the above step 101, the queue process can write the file identifiers of multiple voiceprint files into the shared queue in sequence.
[0036] Step 102: In the initialization stage, the voiceprint data writing process opens the voiceprint file to which the voiceprint data to be written is to be written in an append mode at one time, caches the handle of the voiceprint file, and connects to the shared queue.
[0037] Step 102 can be the preparatory stage or the initialization stage of voiceprint data writing.
[0038] Step 103: When there is a writing requirement, the voiceprint data writing process obtains a first file identifier from the shared queue, and writes the first voiceprint data corresponding to the writing requirement into the first file by using the handle of the first file represented by the first file identifier.
[0039] In this embodiment, when any voiceprint data writing process needs to write voiceprint data, it will take the first file identifier at the head of the shared queue from the shared queue as the first file identifier.
[0040] After any voiceprint data writing process takes out a file identifier from the voiceprint file queue, it finds the corresponding voiceprint file handle according to the file identifier, and then writes the voiceprint data into the corresponding voiceprint file through the voiceprint file handle.
[0041] Here, the file handle is used as an index value to point to the record table of each process opening a file in the kernel.
[0042] When any file identifier is taken out from the shared queue, it means that the file identifier is removed from the shared queue.
[0043] When the first file identifier is rewritten into the shared queue by the voiceprint data writing process, the first file identifier will be written to the end of the shared queue, that is, it becomes the last file identifier in the shared queue.
[0044] In this embodiment, only one process can take out or write a file identifier from the shared queue at the same time.
[0045] For example, in the Multiprocessing module of Python, the Queue class can ensure that when multiple processes try to access the queue simultaneously, only one process can successfully perform operations by maintaining a lock (Locks) internally. The Queue class uses a lock internally to ensure that each operation on the queue (such as put, get, etc.) is atomic, that is, it cannot be interrupted.
[0046] When a process attempts to perform operations such as put (putting a file identifier into the queue) or get (taking a file identifier out of the queue) on the queue, the process first tries to acquire the lock inside the queue. If the lock is available (i.e., not held by other processes), the process will successfully acquire the lock and continue to perform the queue operation. At this time, other processes attempting to acquire the same lock will be blocked until the lock is released. Once the queue operation is completed (e.g., the file identifier has been successfully put in or taken out), the process holding the lock will release the lock. Then, one of the blocked processes will try to acquire the lock again and continue its operation. That is to say, when a process is operating on the queue, other processes must wait until the operation is completed.
[0047] An embodiment of the present invention provides a method for processing voiceprint data based on a queue. Since any voiceprint data writing process obtains the first file identifier from the shared queue in the order of first in first out when it needs to write voiceprint data, it is possible to avoid write conflicts caused by multiple processes writing to the same voiceprint file simultaneously.
[0048] Step 104: After completing the writing of the first voiceprint data, put the first file identifier back into the shared queue.
[0049] After the voiceprint data writing process writes the voiceprint data to the first file, it rewrites the first file identifier into the shared queue. In this way, the voiceprint data writing process or other voiceprint data writing processes can continue to write voiceprint data to the voiceprint file corresponding to the file identifier when needed, realizing the shared writing of the voiceprint file.
[0050] Since the amount of voiceprint data written by each voiceprint data writing process each time is a preset data amount, combined with the shared writing of the voiceprint file and by controlling the amount of data written to the voiceprint file each time, it is possible to effectively avoid the situation where some voiceprint files are frequently written while some other voiceprint files are not written for a long time, thereby realizing the balance of voiceprint file writing.
[0051] Multiple voiceprint data writing processes share access to the shared queue. After taking out different file identifiers from the shared queue, they can write voiceprint data to the voiceprint files corresponding to their respective file identifiers in parallel. In this way, computing resources can be fully utilized to improve the efficiency of voiceprint data writing.
[0052] For example, between the voiceprint data writing process and the queue process, based on the communication between processes, informing the queue process that the first file identifier has been written this time can enable the queue process to write the first file identifier into the shared queue again.
[0053] For another example, informing the thread scheduler that the first file identifier has been written this time by the voiceprint data writing process can enable the thread scheduler to write the first file identifier into the shared queue again.
[0054] In one embodiment, the shared queue has a blocking function, and step 102a further includes: When the shared queue is empty, the operation of the voiceprint data writing process to obtain the file identifier from the shared queue will be blocked until a file identifier is added to the shared queue, and then the first file identifier is taken out from the shared queue.
[0055] For example, when the shared queue is empty, if a certain process obtains an element from the shared queue, since there is no file identifier in the queue, the process will be placed in a blocked state (also known as a waiting state). In this state, the process will not continue to execute subsequent operations, but will wait until there is a file identifier in the shared queue, and then it can continue to execute the operation of taking out the first file identifier from the shared queue.
[0056] In some embodiments, the method may further include: setting a queue buffer.
[0057] In the case where a queue buffer is set, the voiceprint data writing process preferentially reads the first file identifier from the queue buffer. The voiceprint data reads the first file identifier from the queue buffer and deletes the read first file identifier from the queue buffer.
[0058] Correspondingly, maintaining the shared queue includes: reading the voiceprint file identifier from the shared queue and sequentially writing it into the queue buffer. And a queue buffer is set to temporarily store the voiceprint file identifier. When the voiceprint data writing process requests an identifier, it preferentially obtains it from the queue cache. If the queue cache is empty, it obtains it from the queue and replenishes the shared cache.
[0059] Compared with the voiceprint data writing process directly reading the first file identifier from the shared queue, the voiceprint data writing process reads the first file identifier from the queue buffer at a faster rate, thereby further improving the writing rate of the voiceprint data.
[0060] In some embodiments, the method further includes: managing the queue buffer according to a preset mechanism, so that the order in which the voiceprint data writing process reads the voiceprint file identifier from the queue buffer is the same as the order in which it reads the voiceprint file identifier from the shared queue. That is, if one or more voiceprint data writing processes read the voiceprint file identifier from the shared queue in the first order, then the order in which one or more voiceprint data writing processes read the voiceprint file identifier from the queue buffer is also the first order. In other words, the order in which the voiceprint data file identifier is written into the shared queue is the first order.
[0061] Specifically, the voiceprint data writing process can also read the voiceprint file identifier from the queue buffer in a first-in-first-out manner. In some embodiments, in order to still ensure that each file is written sequentially when the voiceprint data writing process reads the file identifier from the queue buffer, a preset mechanism is set. The preset mechanism includes but is not limited to at least one of the following: 1. Ordered filling strategy for the queue buffer, batch ordered filling: When filling the voiceprint file identifier from the shared queue into the queue buffer, a batch ordered method is adopted. For example, each time a fixed number (such as 3 or 10) of file identifiers are continuously read from the shared queue and placed into the queue buffer in the order in which they appear in the shared queue. This can ensure that the file identifiers in the queue buffer are ordered within a certain range. The number of voiceprint file identifiers that can be written into the queue buffer can be set fixedly, for example, 3 or 5, etc. In some embodiments, the number of voiceprint file identifiers that can be written into the queue buffer is related to the number of voiceprint data writing processes. For example, the number of voiceprint file identifiers that can be written into the queue buffer is positively correlated with the number of voiceprint data writing processes. The number m of voiceprint file identifiers that can be written into the queue buffer is equal to the number n of voiceprint data writing processes plus S. S is a positive integer less than or equal to 3.
[0062] 2. Reading rule, sequential reading: When the voiceprint data writing process reads the file identifier from the queue buffer, it reads strictly in the order of the file identifiers in the queue buffer. A queue (such as collections.deque in Python) can be used to implement the queue buffer to ensure the first-in-first-out reading order.
[0063] 3. Add a sequential number to each file identifier. When the writing process reads the file identifier, it also records the maximum number that has been read. When the queue buffer needs to be refilled, start filling from the file identifier in the shared queue that is greater than this maximum number to ensure the continuity of the order.
[0064] 4. Set a synchronization mechanism between the shared queue and the queue buffer, status synchronization: Establish a status synchronization mechanism between the shared queue and the queue buffer. When the order of the file identifiers in the shared queue changes (such as adding or deleting identifiers), the queue buffer is notified in a timely manner to make corresponding adjustments. Synchronization can be achieved through message passing or event triggering.
[0065] 5. Data consistency check, periodically or irregularly check the consistency of the file identifiers in the shared queue and the queue buffer. If inconsistencies are found, such as the existence of identifiers in the queue buffer that do not exist in the shared queue, or the order does not match, make corrections in a timely manner. A hash table can be used to record the status of each file identifier to facilitate quick checking.
[0066] 6. File Identifier Return: If an exception occurs during the writing process, causing a certain file identifier to not be used properly, the writing process needs to return the identifier to the correct position in the queue buffer to ensure the correct order. The identifier can be inserted into the appropriate position in the queue buffer according to its sequential number.
[0067] In one embodiment, before the step of obtaining the first file identifier from the shared queue in step 102a above, the method further includes: When the voiceprint data writing process is initialized, it obtains the file names of each voiceprint file, opens each voiceprint file in append mode according to the file names of each voiceprint file, and saves the file handles of the opened voiceprint files.
[0068] In this embodiment, each voiceprint data writing process can perform the following operations during initialization: obtain the number of voiceprint files according to the process startup parameters, generate a list containing all voiceprint file names according to the number of voiceprint files and a predetermined rule, and traverse the file name list. For each file name traversed, open the corresponding voiceprint file in append write mode, and save the file handle of the opened voiceprint file to a data structure (such as a dictionary). The predetermined rule can include information such as file name prefix and directory.
[0069] For each voiceprint file, the operating system assigns a file handle to the voiceprint file and stores the file handle as an index value in a record table. The record table contains various information about the voiceprint file, such as the location of the file.
[0070] During the operation of the voiceprint data writing process, when there is voiceprint data to be written, the data is appended to the corresponding voiceprint file through the file handle.
[0071] In this embodiment, by opening the voiceprint file in append mode and saving the file handle, the voiceprint data writing process can quickly locate the voiceprint file when voiceprint data needs to be written, without having to reopen the file each time, and can also avoid the voiceprint file from being frequently closed or opened in each process, thus further improving the writing efficiency of the voiceprint file.
[0072] In some embodiments, the method further includes: setting a data buffer for each voiceprint data writing process, where the data buffer is used to temporarily store the voiceprint data to be written; Writing the first voiceprint data corresponding to the writing requirement to the first file includes: writing the first voiceprint data to the data buffer; when the amount of data in the data buffer reaches a set threshold, batch-writing the first voiceprint data to the first file.
[0073] Exemplarily, the set threshold can be determined when the voiceprint data writing process is initialized, can be automatically determined according to historical processing, or can be determined according to user instructions.
[0074] First, write the first voiceprint data into the data buffer area, and then write it into the first file in batches, which can improve the writing speed again.
[0075] In some other embodiments, the data buffer area includes a first buffer area and a second buffer area; the step of writing the first voiceprint data into the data buffer area includes: writing the first voiceprint data into the first buffer area, and when the data volume in the data buffer area reaches the set threshold, writing the first voiceprint data into the second buffer area; the step of batch writing the first voiceprint data into the first file when the data volume in the data buffer area reaches the set threshold includes: when the data volume in the first buffer area reaches the preset threshold, batch writing the first voiceprint data in the first buffer area into the first file.
[0076] The first buffer area and the second buffer area constitute a double-buffer mechanism for data writing. In this way, one buffer area is used for receiving the external writing of voiceprint data, and the other buffer area is used for writing voiceprint data into the voiceprint file, realizing seamless connection of voiceprint data writing.
[0077] In some embodiments, the method further includes: Dynamically adjust the size of the data buffer area according to the operation rate of each voiceprint data writing process.
[0078] Dynamically adjusting the size of the data buffer area according to the operation rate can reduce the buffer waste caused by setting the data buffer area too large, and can also reduce the reduction of the voiceprint data writing speed caused by setting the data buffer area too small.
[0079] Method 1: Dynamic adjustment based on a fixed time interval Monitoring frequency setting: The system sets a fixed time interval, such as every 10 seconds or 20 seconds, etc., to monitor the operation rate of the voiceprint data writing process. Within this time interval, record the number of times the voiceprint data writing process obtains and writes voiceprint data, and use this as a measure of the operation rate.
[0080] Adjustment strategy formulation: If within a fixed time interval, the amount of voiceprint data obtained and written by a certain voiceprint data writing process exceeds the first threshold, for example, 100 pieces (this threshold can be adjusted according to the actual situation), it is determined that its operation rate is relatively fast, and the size of the data buffer is increased. The specific increase can be a proportional increase, for example, increasing the capacity by 20%, or increasing a fixed value, or increasing in a manner positively correlated with the monitored writing rate. If the amount of data obtained and written is less than the second threshold, for example, 50 (this threshold can be adjusted according to the actual situation) pieces, it is determined that its operation rate is relatively slow, and the size of the data buffer is decreased. The specific decrease can be a proportional reduction, for example, reducing the capacity by 10%, or reducing a fixed value, or reducing in a manner positively correlated with the monitored writing rate.
[0081] Method 2: Dynamic adjustment based on the amount of data processed Statistics of the amount of data processed: The system real-time statistics the amount of voiceprint data processed by the voiceprint data writing process. For example, every time 100KB (this threshold can be adjusted according to the actual situation) of data is processed, the processing amount is recorded once.
[0082] Judgment of the adjustment timing: When the cumulative processing amount reaches the specified value (for example, 1MB), the operation rate is judged according to the average time for processing data during this period. If the average time for processing 100KB of data is less than 5 seconds, it indicates that the operation rate is fast; if it is greater than 10 seconds, it indicates that the operation rate is slow.
[0083] Adjustment of the buffer size: If the operation rate is fast, double the capacity of the data buffer; if the operation rate is slow, halve the capacity of the data buffer, but the minimum shall not be less than the initially set minimum value.
[0084] Method 3: Dynamic adjustment based on system load Monitoring of the operating system load: The system continuously monitors the usage of system resources such as CPU and memory as an indicator of system load. For example, when the CPU usage rate exceeds 80% and the memory usage rate exceeds 70%, the system load is considered high; when the CPU usage rate is below 30% and the memory usage rate is below 40%, the system load is considered low.
[0085] Adjustment in combination with the operation rate: For the voiceprint data writing process, when the system load is high, if its operation rate is fast (measured by the amount of data processed per unit time), appropriately reduce the size of the data buffer to avoid excessive occupation of system resources. For example, reduce the size of the data buffer by 30% to release memory for other processes. When the system load is low, if the operation rate is slow, appropriately increase the size of the data buffer to improve the efficiency of the writing process. For example, increase the size of the data buffer by 40%.
[0086] In one embodiment, before the step of writing the voiceprint data into the first file corresponding to the first file identifier in step 102a above, the method further includes: The voiceprint data writing process determines whether to write the voiceprint data into the first file according to whether the current state of the first file meets the first threshold condition.
[0087] Exemplarily, the current state of the first file may include: the total number of times the first file has been written with data (i.e., the total number of writes); the first threshold condition may include: a write count threshold, so as to prevent the data volume written in the voiceprint file from being too large due to an excessive number of writes by restricting the number of writes to the voiceprint file.
[0088] For example, assume that the voiceprint data writing process determines whether to write the voiceprint data into the first file file_A according to whether the value obtained by adding one to the number of times file_A has been written is less than or equal to a preset maximum number of writes (such as 200 times). Or, the voiceprint data writing process determines whether to write the voiceprint data into the first file according to whether the value obtained by adding a preset data volume (such as 5MB) to the data volume that has already been written to the first file file_A is less than or equal to a preset maximum write data volume (such as 150MB).
[0089] Before the voiceprint data writing process writes the voiceprint data into a voiceprint file, it will judge the current state of the voiceprint file and compare it with the first threshold condition. For example, if the first threshold condition is met, the write operation of writing the voiceprint data into the voiceprint file is executed; if the first threshold condition is not met, the write operation of writing the voiceprint data into the voiceprint file is not executed, and the file identifier of another voiceprint file is retrieved from the shared queue again.
[0090] In this embodiment, since the voiceprint data writing process determines whether to write the voiceprint data according to whether the current state of the voiceprint file meets the first threshold condition before writing the voiceprint data into the voiceprint file, this can limit the number of writes to the voiceprint file to prevent the data volume written in the voiceprint file from being too large due to an excessive number of writes, which helps to improve the writing balance of the voiceprint file.
[0091] In one embodiment, in the above steps, the voiceprint data writing process determines whether to write the voiceprint data into the first file according to whether the current state of the first file meets the first threshold condition, including: The voiceprint data writing process determines whether to write the voiceprint data into the first file according to whether the value obtained by adding one to the number of times the first file has been written is less than or equal to a preset maximum number of writes; Alternatively, the voiceprint data writing process determines whether to write the voiceprint data into the first file based on whether the value obtained by adding the amount of data already written in the first file to the preset data amount is less than or equal to the preset maximum write data amount.
[0092] Exemplarily, when the value obtained by adding one to the number of times the first file has been written is less than or equal to the preset maximum number of writes, the voiceprint data writing process performs the operation of writing the voiceprint data into the first file.
[0093] When the value obtained by adding one to the number of times the first file has been written is greater than the preset maximum number of writes, the voiceprint data writing process does not perform the operation of writing the voiceprint data into the first file.
[0094] Exemplarily, when the value obtained by adding the preset data amount to the amount of data already written in the first file is less than or equal to the preset maximum write data amount, the voiceprint data writing process performs the operation of writing the voiceprint data into the first file.
[0095] When the value obtained by adding the preset data amount to the amount of data already written in the first file is greater than the preset maximum write data amount, the voiceprint data writing process does not perform the operation of writing the voiceprint data into the first file.
[0096] In this embodiment, when the voiceprint data writing process determines whether to write the voiceprint data into the first file, it will be based on the number of writes of the file or based on the amount of data already written in the file and the preset data amount, which can effectively alleviate the problem of frequent writing of voiceprint files and excessive amount of data already written, thus ensuring the balance of writing data to the voiceprint file.
[0097] In one embodiment, before the step of rewriting the first file identifier into the shared queue in the above step 102b, the method further includes: The voiceprint data writing process determines whether to delay writing the first file identifier into the shared queue according to whether the current state of the first file meets the second threshold condition.
[0098] Exemplarily, the current state of the first file may include: the difference between the number of times the first file has been written and the average number of times all voiceprint files have been written; the second threshold condition may include: a difference threshold.
[0099] For example, assume that the voiceprint data writing process determines whether to delay writing the file identifier of the first file file_A to the shared queue based on whether the difference in the number of times the first file file_A is written minus the average number of times it is written is greater than a first preset difference (such as 20 times). Alternatively, the voiceprint data writing process determines whether to delay writing the file identifier of the first file file_A to the shared queue based on whether the difference in the amount of data already written to the first file file_A minus the average amount of data is greater than a second preset difference (such as 30 MB).
[0100] When the current state of the first file does not meet the second threshold condition, the voiceprint data writing process delays the writing operation. For example, after a preset delay duration, it performs the operation of writing the first file identifier to the shared queue. Wherein, the preset delay duration can be positively correlated with the difference value.
[0101] In this embodiment, before the voiceprint data writing process rewrites the retrieved file identifier to the shared queue, it first determines whether to delay writing the file identifier based on whether the current state of the voiceprint file meets the second threshold condition. This can limit the timing of rewriting the file identifier. By adding the file identifier to the shared queue at an appropriate time, it can reduce the situation where the voiceprint file is written frequently, thereby helping to improve the balance of writing data to the voiceprint file.
[0102] In one embodiment, in the above steps, the voiceprint data writing process determines whether to delay writing the first file identifier to the shared queue based on whether the current state of the first file meets the second threshold condition, including: The voiceprint data writing process determines whether to delay writing the first file identifier to the shared queue based on whether the difference in the number of times the first file is written minus the average number of times it is written is greater than a first preset difference; the average number of times it is written is the ratio of the total number of times all voiceprint files are written to the total number of voiceprint files; Or, the voiceprint data writing process determines whether to delay writing the first file identifier to the shared queue based on whether the difference in the amount of data already written to the first file minus the average amount of data is greater than a second preset difference; the average amount of data is the ratio of the total amount of data already written to all voiceprint files to the total number of voiceprint files.
[0103] Exemplarily, when the difference in the number of times the first file is written minus the average number of times it is written obtained by the voiceprint data writing process is greater than the first preset difference, it delays writing the first file identifier to the shared queue.
[0104] When the difference in the number of times the first file is written minus the average number of times it is written obtained by the voiceprint data writing process is less than or equal to the first preset difference, it directly writes the first file identifier to the shared queue.
[0105] Exemplarily, when the data volume difference obtained by subtracting the average data volume from the data volume already written in the first file is greater than the second preset difference, the voiceprint data writing process delays writing the first file identifier into the shared queue.
[0106] When the data volume difference obtained by subtracting the average data volume from the data volume already written in the first file is less than or equal to the second preset difference, the voiceprint data writing process directly writes the first file identifier into the shared queue.
[0107] In this embodiment, when the voiceprint data writing process finishes writing the voiceprint data into the first file, it will determine whether to delay writing the first file identifier into the shared queue according to the number of times the first file has been written and the average number of times all voiceprint files have been written, or according to the data volume already written in the file and the average data volume written in all voiceprint files. This can effectively alleviate the problem that voiceprint files are frequently written with data and the data volume already written is too large, thus ensuring the balance of writing data to voiceprint files.
[0108] In one embodiment, the method further includes: When the voiceprint data writing process determines not to write the voiceprint data into the first file, it no longer performs the operation of rewriting the first file identifier into the shared queue, and re-executes the above steps 102a to 102b.
[0109] In this embodiment, when the value obtained by adding one to the number of times the first file has been written is greater than the preset maximum number of writes, or the value obtained by adding the preset data volume to the data volume already written in the first file is greater than the preset maximum data volume to be written, the voiceprint data writing process no longer performs the operation of rewriting the first file identifier into the shared queue. In this way, by stopping the operation of rewriting the file identifier of this file into the shared queue after the first file exceeds the limit, it can ensure that the first file will not cause data overflow due to excessive writing; in addition, it can also avoid the situation where other processes cannot write normally when trying to write voiceprint data to the first file due to the first file identifier being rewritten into the shared queue, ensuring that each process can efficiently perform the operation of writing voiceprint data.
[0110] In one embodiment, the method further includes: The queue process transmits the status information of each voiceprint file periodically monitored to each voiceprint data writing process through the inter-process communication mechanism; wherein, the status information of the voiceprint file includes the number of times the voiceprint file has been written and / or the data volume already written.
[0111] In this embodiment, the queue process can monitor the status of each voiceprint file at a preset time interval to obtain the latest status information of each voiceprint file, and transmit the monitored latest status information to each voiceprint data writing process through an inter-process communication mechanism (e.g., shared memory).
[0112] The status information of each voiceprint file includes: the number of times the voiceprint file has been written and / or the amount of data that has been written. The number of times written can reflect the frequency of the write operation of the voiceprint file, and the amount of data that has been written can reflect the current size and remaining capacity of the voiceprint file.
[0113] In this embodiment, after receiving the status information of each voiceprint file, the voiceprint data writing process can determine whether to continue the write operation according to preset threshold conditions, so as to reduce the occurrence of data overflow or uneven data writing.
[0114] In some embodiments, a voiceprint data processing method based on a queue is provided. The method may include the following steps: Provide a shared queue through a separate process, and the shared queue stores unused voiceprint file identifiers; When the voiceprint extraction process needs to write voiceprint information, it calls the queue through a port, obtains a voiceprint file identifier, writes the voiceprint information into the voiceprint file corresponding to the identifier, and then pushes the identifier back into the shared queue after writing.
[0115] In this embodiment, the voiceprint files are pre-opened in each voiceprint extraction process, and it is necessary to ensure that they are flushed to disk in a timely manner after writing. Although the efficiency of voiceprint extraction in each process may not be the same, the amount of data finally written to each voiceprint file is basically balanced.
[0116] In this embodiment, there is only one queue process (i.e., the queue process in the foregoing embodiment), which is responsible for creating the voiceprint files to be written, creating a shared queue, and providing an interface for cross-process calls, and at the same time pushing the identifiers of the written files into the queue. The queue process starts before the voiceprint extraction process. The queue is of the first-in-first-out type and has a blocking function.
[0117] There are multiple voiceprint extraction processes (i.e., the voiceprint data writing processes in the foregoing embodiments). When initializing, the process obtains the list of files to be written according to the startup parameters, opens these files in append-write mode and saves the file handles, and at the same time connects to the queue of the queue process. When the voiceprint extraction process needs to write voiceprint data, it first obtains a voiceprint file identifier from the above voiceprint file queue, finds the corresponding voiceprint file according to the identifier, then writes the voiceprint data into the file, and finally pushes the just-used voiceprint file identifier into the voiceprint file queue.
[0118] Only one process can open a certain voiceprint file at the same time, so that there is no writing conflict in the voiceprint file. The sizes of different voiceprint files are basically balanced after multiple (e.g., 10,000 times) writes.
[0119] In summary, the technical solution provided by this embodiment can solve problems such as writing conflicts, low writing efficiency, and unbalanced written data when multiple processes (such as python processes) write multiple voiceprint files simultaneously, and realizes efficient and balanced sharing of multiple processes for writing multiple voiceprint files.
[0120] In some embodiments, the method further includes: Obtaining the writing status of the second file pointed to by the second file identifier; If the writing status of the second file is abnormal, an exception reminder is popped up; If the writing status of the second file is normal, the second file identifier is pushed back into the shared queue.
[0121] For example, the writing status can indicate the number of writes, writing frequency, writing rate, writing duration, etc. of the second file. When the writing status reflects that the writing has not been successful for a long time, or the writing is too frequent, or the writing rate is too slow, etc., and these writing parameters are not within the normal writing benchmark range, an exception diagnosis is performed. An exception reminder is given according to the diagnosed exception.
[0122] Possible exceptions include but are not limited to at least one of the following: Insufficient disk space: When attempting to write a file, if an IOError is captured and the error code corresponds to insufficient disk space, it is determined as an exception.
[0123] File permission problem: If a PermissionError exception is captured because of insufficient permissions to write a file.
[0124] Network interruption: When writing data to a server file through an AJAX request, if the request fails and the status code is 0, it may be caused by a network interruption.
[0125] Server error: If the server returns a status code of 500 or other error status codes, it indicates that there is a problem when the server writes the file.
[0126] External storage unavailable: When attempting to write to external storage, check whether the external storage status is MEDIA_MOUNTED. If not, it is determined as an exception.
[0127] File occupied: When opening a file for writing, if a FileNotFoundException is captured and it is caused by the file being occupied by other processes, it is determined as an exception.
[0128] File system corruption: When writing a file, if an OSError is caught and the error message indicates a file system related problem, it is determined as an exception.
[0129] Concurrent write conflict: If writing a file in a multi-threaded or multi-process environment and a ResourceWarning or other concurrency related exception is caught, it is determined as an exception.
[0130] Since the embodiments of the present disclosure perform targeted processing for concurrent writing, especially when a file is detected to be occupied and / or a concurrent write conflict occurs, record the exception event and diagnose whether the maintenance of the current shared queue is normal. If not, reset the shared queue.
[0131] The exception reminders in the embodiments of the present disclosure include but are not limited to immediate reminders. Understand that a reminder is a reminder that can be immediately perceived by the user. For example, a pop-up reminder and / or a message reminder, which may specifically include but are not limited to at least one of the following: Modal pop-up window: In desktop applications, web applications or mobile applications, a modal pop-up window forces the user to interact and prevents the user from operating other interface elements until the pop-up window information is processed. For example, in the Windows system, when a program encounters an error, the "Program not responding" pop-up window appears, and the user must select "Close program" or "Wait" to continue operating the computer; when performing a payment operation on a web page, if the payment fails, the "Payment failed, please check the payment information" pop-up window appears, and only after clicking "OK" can the user return to modify the payment information or retry the payment.
[0132] Non-modal pop-up window: It does not block the user's operation of other interfaces and is usually used to prompt some non-urgent information. For example, the update reminder pop-up window of some software, where the user can choose to update later and then continue using the software; the lyric display pop-up window that appears when switching songs in a music player does not affect the user's operations on the playback progress, volume, etc. Whether to choose a modal pop-up window or a non-modal pop-up window is determined according to the type of exception. For example, a serious exception that causes the inability to continue writing voiceprint data. For example, file crashes, insufficient disk space, etc. can use a modal pop-up window, while network interruptions or server errors, etc. can use a non-modal pop-up window. In short, a non-modal pop-up window can be used for exception types that can be resolved by the device through retries, while a modal pop-up window is used for exception types that cannot be resolved by the device through retries.
[0133] System message: The message notification mechanism built into the operating system. For example, in an Android mobile phone, when the battery power is too low, the system will display a low battery reminder in the notification bar; in the Windows system, when the network connection is abnormal, a prompt icon and message for the network connection being disconnected will pop up in the taskbar.
[0134] In-App Message: Messages sent by the application itself. In social software, when new messages, friend requests, or system notifications (such as account login reminder from different locations) are received, they will be displayed in the in-app message center or in the form of pop-ups; in e-commerce applications, when the price of a product drops or the order status changes (such as shipped, refunded, etc.), message notifications will be pushed to users.
[0135] Figure 2 It is a schematic structural diagram of a voiceprint data writing device according to an embodiment of the present invention. The device is applied to an electronic device, and the electronic device has a queue process and multiple voiceprint data writing processes.
[0136] Referring Figure 2 As shown, the voiceprint data writing device 200 includes: A queue management module 210, configured to create and maintain a shared queue, where the shared queue is a first-in-first-out and blocking-capable queue for storing a voiceprint file identifier queue; A process initialization module 220, configured to open the voiceprint file to be written with voiceprint data in an append-write mode at one time and cache the handle of the voiceprint file during the initialization phase of the voiceprint data writing process, and connect to the shared queue; A writing module 230, configured to, when there is a writing requirement, the voiceprint data writing process obtains a first file identifier from the shared queue, and uses the handle of the first file represented by the first file identifier to write the first voiceprint data corresponding to the writing requirement into the first file; The queue management module 210 is further configured to put the first file identifier back into the shared queue after the first voiceprint data is written.
[0137] In one embodiment, the queue management module is configured to create a queue process by the thread scheduler of the operating system, and create and maintain the shared queue using the queue process; alternatively, the thread scheduler of the operating system creates and maintains the shared queue.
[0138] In one embodiment, the device further includes: a setting module, configured to set a data buffer for each voiceprint data writing process, and the data buffer is used to temporarily store the voiceprint data to be written; Writing the first voiceprint data corresponding to the writing requirement into the first file includes: writing the first voiceprint data into the data buffer; when the data volume in the data buffer reaches a set threshold, batch-writing the first voiceprint data into the first file.
[0139] In one embodiment, the data buffer includes a first buffer and a second buffer; the writing of the first voiceprint data into the data buffer includes: writing the first voiceprint data into the first buffer, and when the data volume in the data buffer reaches a set threshold, writing the first voiceprint data into the second buffer; the batch writing of the first voiceprint data into a first file when the data volume in the data buffer reaches the set threshold includes: when the data volume in the first buffer reaches a preset threshold, batch writing the first voiceprint data in the first buffer into the first file.
[0140] In one embodiment, the device further includes: an adjustment module, configured to dynamically adjust the size of the data buffer according to the operation rates of the respective voiceprint data writing processes.
[0141] In one embodiment, the setting module is further configured to set a queue buffer; the queue buffer is used to temporarily store voiceprint file identifiers. The voiceprint data writing process obtaining a first file identifier from the shared queue includes: the voiceprint data reading the first file identifier from the queue buffer and deleting the read first file identifier in the queue buffer.
[0142] The maintaining of the shared queue includes: reading voiceprint file identifiers from the shared queue and sequentially writing them into the queue buffer.
[0143] In one embodiment, the queue management module is further configured to manage the queue buffer according to a preset mechanism, so that the order in which the voiceprint data writing process reads voiceprint file identifiers from the queue buffer is the same as the order in which it reads voiceprint file identifiers from the shared queue.
[0144] In one embodiment, the device further includes: an obtaining module, configured to obtain the writing status of a second file pointed to by a second file identifier; a popping module, configured to pop up an exception reminder if the writing status of the second file is abnormal; The queue management module is further configured to, if the writing status of the second file is normal, push the second file identifier back into the shared queue.
[0145] In one embodiment, the writing module is further configured to determine whether to write voiceprint data into the first file according to whether the current state of the first file meets the first threshold condition in the voiceprint data writing process. In one embodiment, the writing module is further configured to determine whether to write voiceprint data into the first file according to whether the value obtained by adding one to the number of times the first file has been written is less than or equal to a preset maximum number of writes. In one embodiment, the writing module is further configured to determine whether to write voiceprint data into the first file according to whether the value obtained by adding a preset data volume to the data volume already written in the first file is less than or equal to a preset maximum written data volume. In one embodiment, the writing module is further configured to determine whether to delay writing the first file identifier into the shared queue according to whether the current state of the first file meets the second threshold condition in the voiceprint data writing process. In one embodiment, the writing module is further configured to determine whether to delay writing the first file identifier into the shared queue according to whether the number difference obtained by subtracting the average number of writes from the number of times the first file has been written is greater than a first preset difference; wherein, the average number of writes is the ratio of the total number of times all voiceprint files have been written to the total number of voiceprint files. In one embodiment, the writing module is further configured to determine whether to delay writing the first file identifier into the shared queue according to whether the data volume difference obtained by subtracting the average data volume from the data volume already written in the first file is greater than a second preset difference; wherein, the average data volume is the ratio of the total data volume already written in all voiceprint files to the total number of voiceprint files. In one embodiment, the writing module is further configured to, when determining not to write voiceprint data into the first file, no longer perform the operation of rewriting the first file identifier into the shared queue, and re-execute the operation steps. In one embodiment, the queue process module is further configured to transmit the status information of each voiceprint file periodically monitored by the queue process to each voiceprint data writing process through an inter-process communication mechanism; wherein, the status information of the voiceprint file includes the number of times the voiceprint file has been written and / or the data volume already written.
[0146] It should be noted here that: The description of the above embodiments of the voiceprint data writing device is similar to the description of the above embodiments of the queue-based voiceprint data processing method, and the beneficial effects of the method will not be elaborated. For the technical details not disclosed in the embodiments of the voiceprint data writing device of the embodiments of the present invention, please refer to the description of the embodiments of the queue-based voiceprint data processing method of the embodiments of the present invention.
[0147] Combined with Figure 3As shown in the figure, an embodiment of the present application provides an electronic device, including a processor 10 and a memory 11. Optionally, the device may further include a communication interface 12 and a bus 9. Among them, the processor 10, the communication interface 12, and the memory 11 can complete mutual communication through the bus 9. The communication interface 12 can be used for information transmission. The processor 10 can call the logical instructions in the memory 11 to execute the method for processing voiceprint data based on a queue in the above embodiment.
[0148] In addition, when the logical instructions in the above-mentioned memory 11 are implemented in the form of a software functional unit and sold or used as an independent product, they can be stored in a computer-readable storage medium.
[0149] The memory 11, as a computer-readable storage medium, can be used to store software programs and computer-executable programs, such as the program instructions / modules corresponding to the method in the embodiment of the present application. The processor 10 executes functional applications and data processing by running the program instructions / modules stored in the memory 11, that is, implements the method for processing voiceprint data based on a queue in the above embodiment.
[0150] The memory 11 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system and application programs required for at least one function; the data storage area can store data created according to the use of the electronic device, etc. In addition, the memory 11 may include a high-speed random access memory and may also include a non-volatile memory.
[0151] An embodiment of the present application provides a storage medium storing computer-executable instructions, and the computer-executable instructions are set to execute the above method for processing voiceprint data based on a queue.
[0152] An embodiment of the present application provides a computer program product, the computer program product includes a computer program stored on a storage medium, the computer program includes program instructions, and when the program instructions are executed by a computer, the computer is caused to execute the above method for processing voiceprint data based on a queue.
[0153] The above-mentioned computer-readable storage medium may be a transient computer-readable storage medium or a non-transient computer-readable storage medium.
[0154] The technical solution of the embodiment of the present application can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes one or more instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in the embodiment of the present application. The aforementioned storage medium may be a non-transitory storage medium, including: various media that can store program codes such as USB flash drives, mobile hard disks, read-only memories, random access memories, magnetic disks, or optical discs, or it may also be a transient storage medium.
[0155] In the above embodiments of the present application, the descriptions of each embodiment have their own focuses. For parts not detailed in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.
[0156] The disclosed embodiments or examples of the present application are not exhaustive. They are only illustrations of some embodiments or examples and do not constitute specific limitations on the protection scope of the present disclosure. Without contradiction, each step in a certain embodiment or example can be implemented as an independent embodiment, and the steps can be combined arbitrarily. For example, the solution after removing some steps in a certain embodiment or example can also be implemented as an independent embodiment, and the order of the steps in a certain embodiment or example can be exchanged arbitrarily. Additionally, the optional ways or optional examples in a certain embodiment or example can be combined arbitrarily; moreover, the embodiments or examples can be combined arbitrarily. For example, some or all of the steps of different embodiments or examples can be combined arbitrarily, and a certain embodiment or example can be combined arbitrarily with the optional ways or optional examples of other embodiments or examples.
[0157] In several embodiments provided by the present application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only illustrative. For example, the division of the units can be a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces. The indirect coupling or communication connection of units or modules can be in an electrical or other form.
[0158] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place or distributed to multiple units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0159] In addition, in each embodiment of the present application, the functional units may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of a software functional unit.
[0160] If the above-mentioned integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in each embodiment of the present application. The foregoing storage medium includes: various media such as USB flash drives, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), mobile hard disks, magnetic disks, or optical discs that can store program codes.
[0161] The above are only the preferred embodiments of the present application. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present application, several improvements and refinements can be made, and these improvements and refinements should also be regarded as the protection scope of the present application.
Claims
1. A queue-based voiceprint data processing method, characterized in that: include: Creating and maintaining a shared queue, wherein the shared queue is a first-in-first-out queue with a blocking function, and is used to store a voiceprint file identification queue; The voiceprint data writing process opens the voiceprint file to be written with the voiceprint data in the append writing mode at one time during the initialization phase, caches the handle of the voiceprint file, and connects to the shared queue; When there is a writing requirement, the voiceprint data writing process obtains a first file identifier from the shared queue, and uses the handle of the first file represented by the first file identifier to write the first voiceprint data corresponding to the writing requirement into the first file; After the first voiceprint data is written, the first file identifier is put back into the shared queue.
2. The method according to claim 1, characterized in that The creating and maintaining a shared queue includes: The thread scheduler of the operating system creates a queue process, and uses the queue process to create and maintain the shared queue; or, The thread scheduler of the operating system creates and maintains the shared queue.
3. The queue-based voiceprint data processing method according to claim 1 or 2, characterized in that: Also includes: A data buffer area is set for each voiceprint data writing process, and the data buffer area is used to temporarily store the voiceprint data to be written; Writing the first voiceprint data corresponding to the writing requirement into the first file includes: Writing the first voiceprint data into the data buffer area; When the amount of data in the data buffer reaches a set threshold, the first voiceprint data are written into the first file in batches.
4. The method according to claim 3, characterized in that The data cache area includes a first cache area and a second cache area; the writing of the first voiceprint data into the data cache area includes: writing the first voiceprint data into the first cache area, and when the data volume of the data cache area reaches a set threshold, writing the first voiceprint data into the second cache area; when the data volume of the data cache area reaches a set threshold, writing the first voiceprint data into a first file in batches includes: when the data volume of the first cache area reaches a preset threshold, writing the first voiceprint data in the first cache area into the first file in batches.
5. The method according to claim 3, characterized in that: The method further comprises: The size of the data buffer area is dynamically adjusted according to the operation rate of each voiceprint data writing process.
6. The method according to claim 1 or 2, characterized in that: The method further comprises: Setting a queue buffer area; the queue buffer area is used to temporarily store voiceprint file identifiers; The voiceprint data writing process obtains the first file identifier from the shared queue, including: the voiceprint data reads the first file identifier from the queue buffer area and deletes the first file identifier read from the queue buffer area; The maintaining the shared queue comprises: The voiceprint file identifiers are read from the shared queue and written into the queue buffer area in sequence.
7. The method according to claim 6, characterized in that The method further comprises: The queue buffer area is managed according to a preset mechanism so that the order in which the voiceprint data writing process reads voiceprint file identifiers from the queue buffer area is the same as the order in which the voiceprint file identifiers are read from the shared queue.
8. The method according to claim 6, characterized in that The method further comprises: Get the writing status of the second file pointed to by the second file identifier; If the writing status of the second file is abnormal, an abnormal reminder pops up; If the writing status of the second file is normal, the second file identifier is pushed back into the shared queue.
9. A voiceprint data processing device based on a queue, characterized in that: Applicable to systems with voiceprint data writing function, including: A queue management module, used to create and maintain a shared queue, wherein the shared queue is a first-in-first-out queue with a blocking function, and is used to store a voiceprint file identification queue; A process initialization module, used for the voiceprint data writing process to open the voiceprint file to be written with the voiceprint data in the append writing mode at one time during the initialization phase and cache the handle of the voiceprint file, and connect to the shared queue; A writing module is used for the voiceprint data writing process to obtain a first file identifier from the shared queue when there is a writing demand, and use the handle of the first file represented by the first file identifier to write the first voiceprint data corresponding to the writing demand into the first file; after completing the writing of the first voiceprint data, the first file identifier is placed back into the shared queue.
10. An electronic device, characterized in that: include: A processor and a memory, wherein the memory stores computer executable instructions that can be executed by the processor, and the processor executes the computer executable instructions to implement the queue-based voiceprint data processing method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Data push method, time schedule controller and data push system
CN106375329A
Information interaction method, electronic equipment and storage medium
CN111723190A
Automatic driving image sending method and device, electronic equipment and computer medium
CN115589527A
Method and system for storing multiple concurrent large files
CN119396789A
Efficient implementation of queues and other data structures using processing near memory
US20170255397A1