Voiceprint data writing method, voiceprint data writing device and electronic equipment

By using first-in, first-out shared queues and data volume control during voiceprint data writing, the problems of multi-process write conflicts and imbalances are solved, and efficient and balanced voiceprint file writing is achieved.

CN120256165APending Publication Date: 2025-07-04BEIJING ANDE HEZHONG TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510377589.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-28
Publication Date
2025-07-04

AI Technical Summary

Technical Problem

In the prior art, writing to the same voiceprint file at the same time by multiple processes is likely to lead to write conflicts, and it is difficult to ensure the balance of writing to the voiceprint file.

Method used

The first-in-first-out shared queue mechanism is adopted, and the first process writes the voiceprint file identifier to the shared queue. The second process takes out the file identifier in sequence and writes the voiceprint data, and controls the amount and conditions of each write, delaying the write operation to ensure balance.

Benefits of technology

Avoid write conflicts, improve the balance and efficiency of voiceprint file writing, and make full use of computing resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120256165A_ABST
    Figure CN120256165A_ABST
Patent Text Reader

Abstract

The invention discloses a voiceprint data writing method and device and electronic equipment, and relates to the technical field of data processing. The voiceprint writing method is applied to the electronic equipment, the electronic equipment is provided with a first process and a plurality of second processes, and the voiceprint writing method comprises the following steps: the first process writes respective file identifiers of a plurality of voiceprint files into a first-in first-out shared queue; when any second process needs to write voiceprint data, executing the following operation steps: taking out the target file identifier from the shared queue, and writing the voiceprint data into a target voiceprint file corresponding to the target file identifier; wherein the voiceprint data volume written in each second process each time is the preset data volume; and after the voiceprint data is written into the target voiceprint file, re-writing the target file identifier into the shared queue. According to the technical scheme provided by the embodiment of the invention, the writing conflict caused by writing the same voiceprint file in multiple threads at the same time can be avoided, and meanwhile, the writing balance and efficiency of the voiceprint file are ensured.
Need to check novelty before this filing date? Find Prior Art

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 writing voiceprint data. Background Art

[0002] Voiceprint recognition technology is a type of biometric recognition technology that converts voice 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 process is usually a Python process. 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 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.

[0004] Therefore, how to avoid the writing conflict caused by multiple threads writing to the same voiceprint file simultaneously and ensure the balance of writing to voiceprint files at the same time is a technical problem that urgently needs to be solved. Summary of the Invention

[0005] In view of this, embodiments of the present invention provide a method, apparatus, and electronic device for writing voiceprint data to avoid the writing conflict caused by multiple threads writing to the same voiceprint file simultaneously, and ensure the balance and efficiency of writing to voiceprint files at the same time.

[0006] The technical solution of the present invention is implemented as follows: In a first aspect, a method for writing voiceprint data is provided, which is applied to an electronic device. The electronic device has a first process and multiple second processes. The method includes: The first process writes the file identifier of each of multiple voiceprint files into a first-in, first-out shared queue; When any one of the second processes needs to write voiceprint data, the following operation steps are performed: Take out a target file identifier from the shared queue and write the voiceprint data into the target voiceprint file corresponding to the target file identifier; wherein, the amount of voiceprint data written by each second process each time is a preset data amount; When the writing of the voiceprint data into the target voiceprint file is completed, write the target file identifier back into the shared queue.

[0007] In one embodiment, before the step of retrieving the target file identifier from the shared queue, the method further includes: When the second process is initialized, it obtains the file names of the voiceprint files, opens each of the voiceprint files in append mode according to the file names of the voiceprint files, and saves the file handles of the opened voiceprint files.

[0008] In one embodiment, before the step of writing the voiceprint data into the target voiceprint file corresponding to the target file identifier, the method further includes: The second process determines whether to write the voiceprint data into the target voiceprint file according to whether the current state of the target voiceprint file meets a first threshold condition.

[0009] In one embodiment, the second process determines whether to write the voiceprint data into the target voiceprint file according to whether the current state of the target voiceprint file meets a first threshold condition, including: The second process determines whether to write the voiceprint data into the target voiceprint file according to whether the value obtained by adding one to the number of times the target voiceprint file has been written is less than or equal to a preset maximum number of writes; Alternatively, the second process determines whether to write the voiceprint data into the target voiceprint file according to whether the value obtained by adding the preset data volume to the data volume that has been written into the target voiceprint file is less than or equal to a preset maximum write data volume.

[0010] In one embodiment, before the step of rewriting the target file identifier into the shared queue, the method further includes: When writing the voiceprint data into the target voiceprint file is completed, the second process determines whether to delay writing the target file identifier into the shared queue according to whether the current state of the target voiceprint file meets a second threshold condition.

[0011] In one embodiment, the second process determines whether to delay writing the target file identifier into the shared queue according to whether the current state of the target voiceprint file meets a second threshold condition, including: The second process determines whether to delay writing the target 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 target voiceprint file has been written is greater than a first preset difference; where the average number of writes is the ratio of the total number of writes of all voiceprint files to the total number of voiceprint files; or, The second process determines whether to delay writing the target file identifier into the shared queue based on whether the data volume difference obtained by subtracting the average data volume from the data volume already written in the target voiceprint 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.

[0012] In one embodiment, the method further includes: When the second process determines not to write the voiceprint data into the target voiceprint file, it does not perform the operation of rewriting the target file identifier into the shared queue, and re-executes the operation steps.

[0013] In one embodiment, the method further includes: The first process transmits the status information of each of the voiceprint files periodically monitored to each of the second processes 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.

[0014] In a second aspect, a voiceprint data writing device is provided, which is applied to an electronic device. The electronic device has a first process and multiple second processes. The device includes: A first process module, configured to enable the first process to write the file identifiers of multiple voiceprint files into a first-in, first-out shared queue; A second process module, configured to perform the following operation steps when any one of the second processes needs to write voiceprint data: Take out the target file identifier from the shared queue, and write the voiceprint data into the target voiceprint file corresponding to the target file identifier; wherein, the voiceprint data volume written by each second process each time is a preset data volume; When the writing of the voiceprint data into the target voiceprint file is completed, rewrite the target file identifier into the shared queue.

[0015] In one embodiment, the second process module is further configured to obtain the file names of the voiceprint files during the initialization of the second process, open the voiceprint files in append mode according to the file names of the voiceprint files, and save the file handles of the opened voiceprint files.

[0016] In one embodiment, the second process module is further configured to determine whether to write the voiceprint data into the target voiceprint file according to whether the current state of the target voiceprint file meets a first threshold condition.

[0017] In one embodiment, the second process module is configured to determine whether to write the voiceprint data into the target voiceprint file according to whether the value obtained by adding one to the number of times the target voiceprint file has been written is less than or equal to a preset maximum number of writes.

[0018] In one embodiment, the second process module is configured to determine whether to write the voiceprint data into the target voiceprint file according to whether the value obtained by adding the preset data volume to the data volume already written in the target voiceprint file is less than or equal to a preset maximum write data volume.

[0019] In one embodiment, the second process module is further configured to determine whether to delay writing the target file identifier into the shared queue according to whether the current state of the target voiceprint file meets a second threshold condition when the second process finishes writing the voiceprint data into the target voiceprint file.

[0020] In one embodiment, the second process module is configured to determine whether to delay writing the target 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 target voiceprint 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.

[0021] In one embodiment, the second process module is further configured to determine whether to delay writing the target 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 target voiceprint 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.

[0022] In one embodiment, the second process module is further configured to, when determining not to write the voiceprint data into the target voiceprint file, not perform the operation of rewriting the target file identifier into the shared queue, and re-execute the operation steps.

[0023] In one embodiment, the first process module is further configured to transmit the status information of each of the voiceprint files periodically monitored by the first process to each of the second processes 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.

[0024] 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 writing method provided in any of the above embodiments.

[0025] The technical solutions provided by the embodiments of the present invention at least have the following beneficial effects: 1. Since any second process retrieves the target file identifier from the shared queue in the order of first in first out when writing voiceprint data, it is possible to avoid write conflicts caused by multiple processes writing to the same voiceprint file simultaneously.

[0026] 2. Since the amount of voiceprint data written by each second process each time is a preset amount, and after writing the voiceprint data to the target voiceprint file, the target file identifier is pushed back into the shared queue, it is possible to effectively improve the balance of writing to the voiceprint file, thereby effectively reducing the situation where some voiceprint files are frequently written while other files are not written for a long time.

[0027] 3. Multiple second processes share access to the shared queue. After retrieving different file identifiers from the shared queue in the order of first in first out, they can write voiceprint data to the voiceprint files corresponding to their respective file identifiers in parallel, so as to make full use of computing resources and improve the efficiency of writing voiceprint data. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] 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 of the present application and their descriptions 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 writing method 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

[0029] In order to enable those skilled in the art to better understand the solutions 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 accompanying 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. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

[0030] It should be noted that the terms "first", "second", etc. in the specification, 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 herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units does not 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.

[0031] It should also be noted that the information and data collected by the present invention (for example, 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.

[0032] In the related art, a voiceprint extraction program can extract voiceprint data using multiple processes, 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.

[0033] According to an embodiment of the present invention, an embodiment of a method for writing voiceprint data 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.

[0034] It should be noted that a voiceprint data writing device can be the execution subject of the voiceprint data writing method according to the 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.

[0035] The voiceprint data writing method provided by the embodiment of the present invention can be applied to scenarios such as identity authentication based on voiceprint recognition or speech recognition.

[0036] Figure 1 It is a flowchart of a method for writing voiceprint data according to an embodiment of the present invention. Refer to Figure 1 As shown, the voiceprint data writing method includes the following steps: Step 101: The first process writes the file identifier of each of multiple voiceprint files into a first-in, first-out shared queue.

[0037] The voiceprint data writing method provided by the embodiment of the present invention is applied to an electronic device, and the electronic device has a first process and multiple second processes.

[0038] In this embodiment, the first process is a separate process, and the first process can be called the "queue process". The first process also provides an interface for cross-process calls so that the second process can access the shared queue.

[0039] When the first process starts, it 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 in addition, it 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 times to write to the file, and other parameters.

[0040] In this embodiment, the shared queue can also be called the "voiceprint file queue" and is used to save the file identifiers of each voiceprint file. The shared queue is a queue in a first-in, first-out (FIFO, First In First Out) manner. Each file identifier is arranged in the shared queue in the order of being written, and the file identifier that enters the queue earliest will be processed first.

[0041] In this embodiment, the second process can be referred to as the "voiceprint extraction process". The number of second processes is multiple, and multiple second processes can concurrently process different audio files, generate voiceprint data, and write the voiceprint data into voiceprint files. It can be understood that the duration required for each second 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.

[0042] In some examples, the second 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 second processes can process multiple audio files in parallel to extract voiceprint feature data.

[0043] When the second process starts, it will be connected to the shared queue at the same time, so that the second process can read the file identifiers written by other processes (such as the first process) from the shared queue.

[0044] Here, there is no corresponding relationship between multiple second processes and multiple voiceprint files. The number of voiceprint files can be the same as or different from the number of second processes. For example, the number of voiceprint files can be more than the number of second processes, or less than the number of second processes.

[0045] In this embodiment, the amount of data of each voiceprint data extracted by each second process is the same.

[0046] In some examples, before executing step 101, the first process can create multiple voiceprint files to be written with voiceprint data in advance according to the number of files, and obtain the file identifiers of all voiceprint files.

[0047] 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.

[0048] In some examples, after reaching the preset duration, multiple voiceprint files all store voiceprint data, and the size difference between multiple voiceprint files is less than the preset difference value. Here, the sizes of different voiceprint files are balanced, which is convenient for subsequent distribution of voiceprint recognition tasks according to voiceprint files.

[0049] In the above step 101, the first process can write the file identifiers of multiple voiceprint files into the shared queue in sequence.

[0050] Step 102: When any one of the second processes needs to write voiceprint data, execute steps 102a to 102b.

[0051] Step 102a: Retrieve the target file identifier from the shared queue and write the voiceprint data into the target voiceprint file corresponding to the target file identifier; wherein, the amount of voiceprint data written by each second process each time is a preset amount of data. Step 102b: When the writing of the voiceprint data into the target voiceprint file is completed, rewrite the target file identifier into the shared queue.

[0052] In this embodiment, when any second process needs to write voiceprint data, it will retrieve the first file identifier at the head of the shared queue from the shared queue as the target file identifier.

[0053] After any second process retrieves a file identifier from the voiceprint file queue, it locates 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.

[0054] 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.

[0055] Once any file identifier is retrieved from the shared queue, it means that the file identifier is removed from the shared queue.

[0056] When the target file identifier is rewritten into the shared queue by the second process, the target file identifier will be written to the end of the shared queue, that is, it becomes the last file identifier in the shared queue.

[0057] In this embodiment, only one process can retrieve or write a file identifier from the shared queue at the same time.

[0058] For example, in the Multiprocessing module of Python, the Queue class can ensure that when multiple processes attempt to access the queue simultaneously, only one process can successfully perform operations by maintaining internal locks (Locks). The Queue class uses locks internally to ensure that each operation on the queue (such as put, get, etc.) is atomic, that is, it cannot be interrupted.

[0059] When a process attempts to perform operations such as put (putting a file identifier into the queue) or get (retrieving a file identifier from the queue) on the queue, the process first attempts 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 (for example, the file identifier has been successfully put in or retrieved), the process holding the lock will release the lock. Then, one of the blocked processes will attempt 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.

[0060] An embodiment of the present invention provides a method for writing voiceprint data. Since any second process obtains a target file identifier from the shared queue in the order of first in first out when writing voiceprint data is required, it is possible to avoid write conflicts caused by multiple processes writing the same voiceprint file simultaneously.

[0061] After the second process writes the voiceprint data into the target voiceprint file, it rewrites the target file identifier into the shared queue. In this way, the second process or other second processes can continue to write voiceprint data into the voiceprint file corresponding to the file identifier when needed, realizing the shared writing of voiceprint files.

[0062] Since the amount of voiceprint data written by each second process each time is a preset amount, combined with the shared writing of voiceprint files 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 effectively improving the balance of voiceprint file writing.

[0063] Multiple second processes share access to the shared queue. After retrieving different file identifiers from the shared queue, they can write voiceprint data into 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.

[0064] 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 second process to retrieve a file identifier from the shared queue will be blocked until a file identifier is added to the shared queue, and then the operation of retrieving a file identifier from the shared queue is performed.

[0065] For example, when the shared queue is empty, if a certain thread retrieves an element (i.e., a file identifier) from the shared queue, since there is no file identifier in the queue, the thread will be placed in a blocked state (also known as the waiting state). In this state, the thread will not continue to execute subsequent operations but will wait until there is a file identifier in the shared queue and then can continue to execute the operation of retrieving the target file identifier from the shared queue.

[0066] In one embodiment, before the step of retrieving the target file identifier from the shared queue in step 102a above, the method further includes: When the second 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.

[0067] In this embodiment, each second 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 the 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). Here, the predetermined rule may include information such as file name prefix and directory.

[0068] 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 storage location of the file.

[0069] During the running of the second process, when there is voiceprint data to be written, the data is appended to the corresponding voiceprint file through the file handle.

[0070] In this embodiment, by opening the voiceprint file in append mode and saving the file handle, the second process can quickly locate the voiceprint file when it needs to write voiceprint data without having to reopen the file each time, and at the same time 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.

[0071] In one embodiment, before the step of writing the voiceprint data into the target voiceprint file corresponding to the target file identifier in step 102a above, the method further includes: The second process determines whether to write the voiceprint data into the target voiceprint file according to whether the current state of the target voiceprint file meets the first threshold condition.

[0072] Exemplarily, the current state of the target voiceprint file may include: the total number of times data has been written to the target voiceprint file (i.e., the total number of writes); the first threshold condition may include: a write count threshold, so as to prevent an excessive amount of data written to the voiceprint file due to a high write count by restricting the number of times the voiceprint file is written.

[0073] For example, assume that the second process determines whether to write voiceprint data to the target voiceprint file file_A based on 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 write count (such as 200 times). Alternatively, the second process determines whether to write voiceprint data to the target voiceprint file based on whether the value obtained by adding a preset data volume (such as 5MB) to the data volume already written to the target voiceprint file file_A is less than or equal to a preset maximum write data volume (such as 150MB).

[0074] Before the second process writes voiceprint data to 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 voiceprint data to the voiceprint file is executed; if the first threshold condition is not met, the write operation of writing voiceprint data to the voiceprint file is not executed, and the file identifier of another voiceprint file is retrieved from the shared queue again.

[0075] In this embodiment, since the second process determines whether to write voiceprint data based on whether the current state of the voiceprint file meets the first threshold condition before writing the voiceprint data to the voiceprint file, this can limit the number of times the voiceprint file is written, so as to prevent an excessive amount of data written to the voiceprint file due to a high write count, which helps to improve the writing balance of the voiceprint file.

[0076] In one embodiment, in the above steps, the second process determines whether to write voiceprint data to the target voiceprint file based on whether the current state of the target voiceprint file meets the first threshold condition, including: The second process determines whether to write voiceprint data to the target voiceprint file based on whether the value obtained by adding one to the number of times the target voiceprint file has been written is less than or equal to a preset maximum write count; Or, the second process determines whether to write voiceprint data to the target voiceprint file based on whether the value obtained by adding a preset data volume to the data volume already written to the target voiceprint file is less than or equal to a preset maximum write data volume.

[0077] Exemplarily, when the value obtained by adding one to the number of times the target voiceprint file has been written is less than or equal to a preset maximum write count, the second process executes the operation of writing voiceprint data to the target voiceprint file.

[0078] When the value obtained by incrementing the write count of the target voiceprint file by the second process is greater than the preset maximum write count, the operation of writing the voiceprint data into the target voiceprint file is not performed.

[0079] Exemplarily, when the value obtained by adding the preset data volume to the data volume already written in the target voiceprint file is less than or equal to the preset maximum write data volume, the second process performs the operation of writing the voiceprint data into the target voiceprint file.

[0080] When the value obtained by adding the preset data volume to the data volume already written in the target voiceprint file is greater than the preset maximum write data volume, the second process does not perform the operation of writing the voiceprint data into the target voiceprint file.

[0081] In this embodiment, when the second process determines whether to write the voiceprint data into the target voiceprint file, it will be based on the write count of the file, or based on the data volume already written in the file and the preset data volume. This can effectively alleviate the problems of the voiceprint file being frequently written with data and the data volume already written being too large, thereby ensuring the balance of writing data to the voiceprint file.

[0082] In one embodiment, before the step of rewriting the target file identifier into the shared queue in the above step 102b, the method further includes: When the voiceprint data is written into the target voiceprint file, the second process determines whether to delay writing the target file identifier into the shared queue according to whether the current state of the target voiceprint file meets the second threshold condition.

[0083] Exemplarily, the current state of the target voiceprint file may include: the difference between the write count of the target voiceprint file and the average write count of all voiceprint files; the second threshold condition may include: a difference threshold.

[0084] For example, assume that when the second process finishes writing the voiceprint data into the target voiceprint file, the second process determines whether to delay writing the file identifier of the target voiceprint file file_A into the shared queue according to whether the difference in the number of times obtained by subtracting the average write count from the write count of the target voiceprint file file_A is greater than a first preset difference (such as 20 times); if the difference in the number of times is greater than the first preset difference, the second threshold condition is met, that is, it is determined to delay writing the target file identifier into the shared queue; if the difference in the number of times is less than or equal to the first preset difference, the second threshold condition is not met, that is, it is determined not to delay writing the target file identifier into the shared queue.

[0085] For another example, when the second process finishes writing the voiceprint data into the target voiceprint file, the second process determines whether to delay writing the file identifier of the target voiceprint file file_A 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 target voiceprint file file_A is greater than a second preset difference (such as 30MB); if the data volume difference is greater than the second preset difference, the second threshold condition is met, that is, it is determined to delay writing the target file identifier into the shared queue; if the data volume difference is less than or equal to the second preset difference, the second threshold condition is not met, that is, it is determined not to delay writing the target file identifier into the shared queue.

[0086] When the current state of the target voiceprint file meets the second threshold condition, the second process delays the write operation. For example, starting from the moment when the second process finishes writing the voiceprint data into the target voiceprint file, the operation of writing the target file identifier into the shared queue is performed after delaying for a preset duration. Wherein, the preset duration can be positively correlated with the difference.

[0087] When the current state of the target voiceprint file does not meet the second threshold condition, the second process does not delay the write operation of writing the target file identifier into the shared queue. That is to say, when the second process finishes writing the voiceprint data into the target voiceprint file, the operation of writing the target file identifier into the shared queue is performed immediately.

[0088] In this embodiment, before the second process rewrites the retrieved file identifier into the shared queue, it first determines whether to delay writing the file identifier according to whether the current state of the voiceprint file meets the second threshold condition, which can limit the timing of the file identifier being rewritten. By adding the file identifier back to the shared queue at an appropriate time, the situation where the voiceprint file is frequently written can be reduced, which helps to improve the balance of writing data to the voiceprint file.

[0089] In one embodiment, in the above steps, the second process determines whether to delay writing the target file identifier into the shared queue according to whether the current state of the target voiceprint file meets the second threshold condition, including: The second process determines whether to delay writing the target file identifier into the shared queue according to whether the number difference obtained by subtracting the average number of times written from the number of times the target voiceprint file has been written is greater than a first preset difference; the average number of times written is the ratio of the total number of times all voiceprint files have been written to the total number of voiceprint files; Or, the second process determines whether to delay writing the target 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 target voiceprint file is greater than a second preset difference; 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.

[0090] Exemplarily, when the voiceprint data is written to the target voiceprint file, the second process determines the difference in the number of times the target voiceprint file has been written minus the average number of times written; when the difference in the number of times is greater than the first preset difference, the target file identifier is delayed from being written to the shared queue; when the difference in the number of times is less than or equal to the first preset difference, the target file identifier is directly written to the shared queue.

[0091] Exemplarily, when the voiceprint data is written to the target voiceprint file, the second process determines the difference in the amount of data that has been written to the target voiceprint file minus the average amount of data; when the difference in the amount of data is greater than the second preset difference, the target file identifier is delayed from being written to the shared queue; when the difference in the amount of data is less than or equal to the second preset difference, the target file identifier is directly written to the shared queue.

[0092] In this embodiment, when the second process finishes writing the voiceprint data to the target voiceprint file, it determines whether to delay writing the target file identifier to the shared queue based on the number of times the target voiceprint file has been written and the average number of times written for all voiceprint files, or based on the amount of data that has been written to the file and the average amount of data written for all voiceprint files. This can effectively alleviate the problem that a certain or certain voiceprint files are frequently written with data and the amount of data that has been written is too large, thus ensuring the balance of writing data to the voiceprint files.

[0093] In one embodiment, the method further includes: When the second process determines not to write the voiceprint data to the target voiceprint file, it does not perform the operation of rewriting the target file identifier to the shared queue, and re-executes the above steps 102a to 102b.

[0094] In this embodiment, when the value obtained by adding one to the number of times the target voiceprint file has been written is greater than the preset maximum number of writes, or when the value obtained by adding the preset amount of data to the amount of data that has been written to the target voiceprint file is greater than the preset maximum amount of written data, the second process does not perform the operation of rewriting the target file identifier to the shared queue. In this way, by stopping the operation of rewriting the file identifier of the target voiceprint file to the shared queue after the target voiceprint file exceeds the limit, it can ensure that the target voiceprint file will not have a data overflow problem 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 target voiceprint file due to the target file identifier being rewritten to the shared queue, thus ensuring that each process can efficiently perform the operation of writing voiceprint data.

[0095] In one embodiment, the method further includes: The first process transmits the status information of each voiceprint file periodically monitored to each second 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 amount of data that has been written.

[0096] In this embodiment, the first 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 second process through an inter-process communication mechanism (e.g., shared memory).

[0097] 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. Among them, 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.

[0098] In this embodiment, after receiving the status information of each voiceprint file, the second process can determine whether to continue the write operation according to a preset threshold condition, so as to reduce the occurrence of data overflow or uneven data writing.

[0099] In some embodiments, a method for writing voiceprint data is provided, and the method may include the following steps: Step S10: Provide a shared queue through a separate process, and the shared queue stores unused voiceprint file identifiers; Step S20: 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.

[0100] In this embodiment, the voiceprint files are pre-opened in each voiceprint extraction process, and it is necessary to ensure that they are written to disk in a timely manner. Although the efficiency of voiceprint extraction may not be the same for each process, the amount of data finally written to each voiceprint file is basically balanced.

[0101] In this embodiment, there is only one queue process (i.e., the first 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 shared queue is of the first-in-first-out type and has a blocking function.

[0102] There are multiple voiceprint extraction processes (i.e., the second process in the foregoing embodiments). During initialization, each process obtains a list of files to be written according to the startup parameters, opens these files in append mode, saves the file handles, and connects to the queue of the queue process. When a voiceprint extraction process needs to write voiceprint data, it first retrieves a voiceprint file identifier from the shared queue, locates the corresponding voiceprint file according to the identifier, then writes the voiceprint data to the file, and finally pushes the retrieved voiceprint file identifier back into the shared queue.

[0103] 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 being written multiple times (e.g., 10,000 times).

[0104] In summary, the technical solution provided in this embodiment can solve problems such as writing conflicts, low writing efficiency, and unbalanced written data when multiple processes (such as python processes) write to multiple voiceprint files at the same time, and realizes high-efficiency and balanced sharing of multiple processes for writing to multiple voiceprint files.

[0105] 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 first process and multiple second processes.

[0106] Refer to Figure 2 As shown, the voiceprint data writing device 200 includes: A first process module 201, configured to write the file identifier of each of multiple voiceprint files into a first-in-first-out shared queue by the first process; A second process module 202, configured to perform the following operation steps when any second process needs to write voiceprint data: Retrieve a target file identifier from the shared queue, and write the voiceprint data into the target voiceprint file corresponding to the target file identifier; wherein, the amount of voiceprint data written by each second process each time is a preset data amount; When the writing of the voiceprint data into the target voiceprint file is completed, write the target file identifier back into the shared queue.

[0107] In one embodiment, the second process module is further configured to obtain the file names of each voiceprint file during the initialization of the second process, open each voiceprint file in append mode according to the file names of each voiceprint file, and save the file handles of the opened voiceprint files.

[0108] In one embodiment, the second process module is further configured to determine whether to write the voiceprint data into the target voiceprint file according to whether the current state of the target voiceprint file meets a first threshold condition.

[0109] In one embodiment, the second process module is further configured to determine whether to write the voiceprint data into the target voiceprint file according to whether the value obtained by adding 1 to the number of times the target voiceprint file has been written is less than or equal to a preset maximum number of writes.

[0110] In one embodiment, the second process module is further configured to determine whether to write the voiceprint data into the target voiceprint file according to whether the value obtained by adding a preset data volume to the data volume that has been written into the target voiceprint file is less than or equal to a preset maximum write data volume.

[0111] In one embodiment, the second process module is further configured to determine whether to delay writing the target file identifier into the shared queue according to whether the current state of the target voiceprint file meets the second threshold condition when the second process finishes writing the voiceprint data into the target voiceprint file.

[0112] In one embodiment, the second process module is further configured to determine whether to delay writing the target 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 target voiceprint 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.

[0113] In one embodiment, the second process module is further configured to determine whether to delay writing the target file identifier into the shared queue according to whether the data volume difference obtained by subtracting the average data volume from the data volume that has been written into the target voiceprint file is greater than a second preset difference; wherein, the average data volume is the ratio of the total data volume that has been written into all voiceprint files to the total number of voiceprint files.

[0114] In one embodiment, the second process module is further configured to, when determining not to write the voiceprint data into the target voiceprint file, not perform the operation of rewriting the target file identifier into the shared queue, and re-execute the operation steps.

[0115] In one embodiment, the first process module is further configured to transmit the status information of each voiceprint file periodically monitored by the first process to each second 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 that has been written.

[0116] 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 voiceprint data writing method, and the beneficial effects of the method are not described in detail. 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 voiceprint data writing method of the embodiments of the present invention.

[0117] Combined withFigure 3 As shown in Figure 3 , an embodiment of the present application provides an electronic device, including a processor 10 and a memory 11. Optionally, the electronic 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 voiceprint data writing method of the above embodiment.

[0118] 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.

[0119] 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 voiceprint data writing method in the above embodiment.

[0120] 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.

[0121] 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 voiceprint data writing method.

[0122] 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. When the program instructions are executed by a computer, the computer is caused to execute the above voiceprint data writing method.

[0123] The above computer-readable storage medium may be a transient computer-readable storage medium or a non-transient computer-readable storage medium.

[0124] 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 such as USB flash drives, mobile hard disks, read-only memories, random access memories, magnetic disks, or optical discs that can store program codes, or it may also be a transient storage medium.

[0125] In the above embodiments of the present application, the descriptions of each embodiment have their own focuses. For the parts not detailed in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0126] 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; furthermore, 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.

[0127] In the 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.

[0128] 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.

[0129] In addition, in each embodiment of the present application, the functional units can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit.

[0130] 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 this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can 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.

[0131] 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 method for writing voiceprint data, characterized in that, Applied to an electronic device, the electronic device having a first process and a plurality of second processes, the method comprising: The first process writes the file identifier of each of the plurality of voiceprint files into a first-in first-out shared queue; When any one of the second processes needs to write voiceprint data, the following operation steps are performed: Take out the target file identifier from the shared queue, and write the voiceprint data into the target voiceprint file corresponding to the target file identifier; wherein, the amount of voiceprint data written by each second process each time is a preset data amount; When the writing of the voiceprint data into the target voiceprint file is completed, write the target file identifier back into the shared queue.

2. The method according to claim 1, characterized in that, Before the step of taking out the target file identifier from the shared queue, the method further comprises: When initializing, the second process obtains the file names of the respective voiceprint files, opens the respective voiceprint files in append mode according to the file names of the respective voiceprint files, and saves the file handles of the opened respective voiceprint files.

3. The method according to claim 1, wherein Before the step of writing the voiceprint data into the target voiceprint file corresponding to the target file identifier, the method further comprises: The second process determines whether to write the voiceprint data into the target voiceprint file according to whether the current state of the target voiceprint file meets a first threshold condition.

4. The method according to claim 3, wherein The second process determines whether to write the voiceprint data into the target voiceprint file according to whether the current state of the target voiceprint file meets a first threshold condition, including: The second process determines whether to write the voiceprint data into the target voiceprint file according to whether the value obtained by adding one to the number of times the target voiceprint file has been written is less than or equal to a preset maximum number of writes; Alternatively, the second process determines whether to write the voiceprint data into the target voiceprint file according to whether the value obtained by adding the preset data amount to the amount of data already written in the target voiceprint file is less than or equal to a preset maximum amount of written data.

5. The method according to claim 1, characterized in that, Before the step of writing the target file identifier back into the shared queue, the method further comprises: When the writing of the voiceprint data into the target voiceprint file is completed, the second process determines whether to delay writing the target file identifier into the shared queue according to whether the current state of the target voiceprint file meets a second threshold condition.

6. The method according to claim 5, characterized in that, The second process determines whether to delay writing the target file identifier into the shared queue according to whether the current state of the target voiceprint file meets a second threshold condition, including: The second process determines whether to delay writing the target 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 target voiceprint 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; or, The second process determines whether to delay writing the target 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 target voiceprint 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.

7. The method according to claim 3, wherein The method further includes: When the second process determines not to write the voiceprint data into the target voiceprint file, it does not perform the operation of rewriting the target file identifier into the shared queue and re-executes the operation step.

8. The method according to any one of claims 3 to 7, characterized in that, The method further includes: The first process transmits the status information of each of the voiceprint files periodically monitored to each of the second processes 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.

9. A voiceprint data writing device, characterized in that, Applied to an electronic device, the electronic device has a first process and multiple second processes, and the device includes: A first process module, configured for the first process to write the file identifiers of multiple voiceprint files into a first-in, first-out shared queue; A second process module, configured for any one of the second processes to perform the following operation steps when writing voiceprint data is required: Take out the target file identifier from the shared queue and write the voiceprint data into the target voiceprint file corresponding to the target file identifier; wherein, the voiceprint data volume written by each second process each time is a preset data volume; When finishing writing the voiceprint data into the target voiceprint file, rewrite the target file identifier into the shared queue.

10. An electronic device, characterized in that, It includes: A processor and a memory, 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 writing method according to any one of claims 1 to 8.