Audio conversion method and device, electronic equipment and storage medium
By using sample rate magnification and splicing data in the audio conversion method, the fluency problem between audio data is solved, and efficient compatibility and low consumption conversion of audio files are achieved.
Patent Information
- Application Number
- CN202410846264.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-27
- Publication Date
- 2024-11-12
AI Technical Summary
Existing audio sample rate conversion methods have fluency problems between multiple audio data, resulting in poor user experience.
By obtaining the audio data to be converted and the sampling rate magnification, determine the splicing data to connect the audio data, use the formula such as PCM'n=PCM1×(m-n)÷m+PCM2×(n÷m) to convert the audio data to ensure multiple segments Fluent playback between audio data.
It realizes smooth connection between audio data between different sampling rates, improves the compatibility and playability of audio files, and reduces CPU and memory consumption.
Smart Images

Figure CN118942473A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of audio processing technology, and in particular to an audio conversion method and device, electronic equipment, and storage medium. Background Art
[0002] Currently, different audio devices may support different sampling rates. For example, some audio devices may support sampling rates such as: 8kHz. While other audio devices may support sampling rates such as: 44.1kHz. By converting the audio to the appropriate sampling rate, you can ensure the compatibility and playability of the audio file on various audio devices.
[0003] The existing audio sampling rate conversion scheme usually converts the sampling rates of multiple segments of collected audio data separately to obtain target audio data that can be adapted to the audio device for playback. However, when the sampling rates of multiple segments of collected audio data are converted separately, the target audio data segments played continuously are not smooth, which affects the user experience.
[0004] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present application, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0005] In order to provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. The summary is not an extensive review, nor is it intended to identify key / critical components or delineate the scope of protection of these embodiments, but rather serves as a prelude to the detailed description that follows.
[0006] The embodiments of the present application provide an audio conversion method and device, an electronic device, and a storage medium to improve the fluency between audio data when the audio data after the sampling rate conversion is played continuously.
[0007] An embodiment of the present application provides an audio conversion method, including: obtaining audio data to be converted and a sampling rate multiplier; determining splicing data according to the sampling rate multiplier and a previous frame of audio data of the audio data to be converted, the splicing data including a sampling point to be spliced or a position number to be spliced; determining audio data to be connected according to the splicing data and the audio data to be converted; converting the audio data to be connected according to the sampling rate multiplier to obtain first target audio data.
[0008] It can be understood that usually a segment of audio data will contain multiple sampling points. When a segment of audio data is converted according to the sampling rate, since the sampling points in the same segment of audio data are continuous, the processed audio data can also be played smoothly. When two segments of continuous audio data are converted separately, only the sampling points in the first segment of audio data will be processed, and the sampling points in the second segment of audio data will be processed. At this time, there is no audio information in the second segment of audio data that is connected with the first segment of audio data, and then when the two segments of continuous audio data that have been converted are played continuously, there will be a problem of not being smooth. In the present application, the splicing data that can assist in the connection is determined by the sampling rate multiplier and the previous frame of audio data of the audio data to be converted, and then the audio data to be converted is converted into the audio data to be connected that can be connected with the previous frame of audio data according to the splicing data, so that after the multiple segments of audio data are converted according to the sampling rate multiplier, the multiple segments of audio data can still be played smoothly.
[0009] Furthermore, the sampling rate multiplier is obtained in the following manner: obtaining a preset original sampling rate and a preset target sampling rate; and taking the quotient of the target sampling rate and the original sampling rate as the sampling rate multiplier.
[0010] In the above implementation, in audio processing and editing, it may be necessary to convert the audio to different sampling rates to meet the specific requirements or standards of different audio playback devices. The sampling rate multiplier can be simply and quickly calculated using the target sampling rate and the original sampling rate, thereby facilitating the subsequent accurate conversion of the audio data to be converted based on the sampling rate multiplier.
[0011] Further, determining the splicing data according to the sampling rate multiplier and the previous frame of audio data of the audio data to be converted includes: when the sampling rate multiplier represents an increase in the sampling rate, taking a sampling point at the end of the previous frame of audio data of the audio data to be converted as a sampling point to be spliced; and / or, when the sampling rate multiplier represents a decrease in the sampling rate, obtaining the data amount of the previous frame of audio data of the audio data to be converted; taking the remainder of the reciprocal of the sampling rate multiplier using the data amount; and determining the remainder as the sequence number of the position to be spliced.
[0012] In the above-mentioned implementation, when the sampling rate multiplier represents an increase in the sampling rate, by using a sampling point at the end of the previous frame of audio data of the audio data to be converted as the sampling point to be spliced, it is convenient to determine the connection relationship between the audio data to be connected and the previous frame of audio data. When the sampling rate multiplier represents a decrease in the sampling rate, since the sampling rate multiplier and the data volume of the audio data to be converted may not be integer multiples, there may be redundant sampling points in the previous frame of audio data that do not participate in the conversion of the previous frame of audio data. Therefore, the sequence number of the position to be spliced is determined by the data volume of the previous frame of audio data, which can facilitate the conversion of the audio data to be connected to essentially involve the sampling points of the previous frame of audio data according to the sequence number of the position to be spliced, so that after the multiple audio data segments are converted according to the sampling rate multiplier, the multiple audio data segments can be played smoothly.
[0013] Further, converting the audio data to be connected according to the sampling rate multiplier to obtain the first target audio data includes: when the sampling rate multiplier represents the sampling rate increase, for every two consecutive sampling points in the audio data to be connected, by calculating PCM'n=PCM1×﹙﹙m-n﹚÷m﹚+PCM2×﹙n÷m﹚, obtaining the first target sampling point; each of the first target sampling points forms the first target audio data; wherein PCM'n is the nth first target sampling point of two consecutive sampling points; PCM1 is one of the two consecutive sampling points; PCM2 is another sampling point of two consecutive sampling points; n=0, ...m; m is the sampling rate multiplier; and / or, in the case where the sampling rate multiplier represents a decrease in the sampling rate, a second target sampling point is obtained by calculating PCM"r=PCMI(r×(1 / m)), and each of the second target sampling points forms the first target audio data; wherein PCM"r is the rth first target sampling point; PCMI(r×(1 / m)) is the 1 / m×rth sampling point in the audio data to be connected; r=0, ...p; the value of p is equal to the total number of sampling points of the audio data to be connected multiplied by the sampling rate multiplier.
[0014] In the above-mentioned implementation, the prior art usually performs sampling rate conversion by using an open source library on an electronic device, such as the FFmpeg open source library. However, when performing audio conversion by setting an open source library in an electronic device, there are usually a large number of floating point operations in the open source library, which consumes a relatively high amount of CPU (Central Processing Unit) and memory of the electronic device. At the same time, the open source library itself is relatively large, and the Flash (flash memory) space of the electronic device occupied by storing the open source library in the electronic device for calculation is relatively large. Through the above formula, sampling rate conversion can be easily realized, and then the audio data to be converted that is not supported by the audio device can be converted into the target audio data supported by the audio device for playback under the condition that the CPU and memory consumption of the audio device are extremely low.
[0015] Furthermore, determining the spliced data based on the sampling rate multiplier and the previous frame of audio data of the audio data to be converted includes: judging whether the audio data to be converted is the first input data; and if the audio data to be converted is not the first input data, determining the spliced data based on the sampling rate multiplier and the previous frame of audio data of the audio data to be converted.
[0016] In the above implementation, only when the audio data to be converted is not the audio data input for the first time, the previous frame of audio data will exist, and it is necessary to smoothly connect with the previous frame of audio data during playback. Therefore, when the audio data to be converted is not the audio data input for the first time, determining the splicing data for the audio data to be converted can facilitate smooth playback of the converted multiple audio data.
[0017] Furthermore, after determining whether the audio data to be converted is first-time input data, the method further includes: when the audio data to be converted is first-time input data, converting the audio data to be converted according to the sampling rate multiplier to obtain second target audio data.
[0018] In the above implementation, the audio data to be converted that is input for the first time does not have the previous frame of audio data, so the audio data to be converted can be directly converted according to the sampling rate multiplier.
[0019] Furthermore, after obtaining the audio data to be converted and the sampling rate multiplier, the method also includes: when the sampling rate multiplier represents an increase in the sampling rate, obtaining a sampling point at the end of the audio data to be converted, and recording the value of the sampling point to a first preset position; when the sampling rate multiplier represents a decrease in the sampling rate, obtaining the data amount of the audio data to be converted, and recording the data amount to a second preset position.
[0020] In the above implementation, after each time the audio to be converted is obtained, the last sampling point of the audio to be converted or the data amount of the audio to be converted is directly recorded to a preset position according to the sampling rate multiplier. When the next segment of audio to be converted is converted, the required data can be directly read for calculation, thereby facilitating the subsequent splicing of the audio to be converted.
[0021] An embodiment of the present application provides an audio conversion device, including: an acquisition module, used to acquire audio data to be converted and a sampling rate multiplier; a splicing data determination module, used to determine splicing data according to the sampling rate multiplier and the previous frame of audio data of the audio data to be converted, the splicing data including the sampling point to be spliced or the sequence number of the position to be spliced; a to-be-joined audio determination module, used to determine the to-be-joined audio data according to the splicing data and the to-be-converted audio data; a conversion module, used to convert the to-be-joined audio data according to the sampling rate multiplier to obtain first target audio data.
[0022] An embodiment of the present application provides an electronic device, including 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 above-mentioned audio conversion method.
[0023] In some embodiments, the storage medium stores computer executable instructions, and when the computer executable instructions are called and executed by the processor, the computer executable instructions enable the processor to implement the above-mentioned audio conversion method.
[0024] The above general description and the following description are exemplary and explanatory only and are not intended to limit the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] One or more embodiments are exemplarily described by corresponding drawings, and these exemplary descriptions and drawings do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings are considered similar elements, and the drawings do not constitute a scale limitation, and wherein:
[0026] Figure 1 is a schematic diagram of an audio conversion method provided in an embodiment of the present application;
[0027] Figure 2 is a schematic diagram of another audio conversion method provided in an embodiment of the present application;
[0028] Figure 3 is a schematic diagram of an audio conversion device provided in an embodiment of the present application;
[0029] Figure 4 It is a schematic diagram of an electronic device provided in an embodiment of the present application.
[0030] Reference numerals:
[0031] 1: Acquisition module; 2: Splicing data determination module; 3: To-be-connected audio determination module; 4: Conversion module; 5: Processor; 6: Bus; 7: Memory; 8: Communication interface. DETAILED DESCRIPTION
[0032] In order to be able to understand the features and technical contents of the embodiments of the present application in more detail, the implementation of the embodiments of the present application is described in detail below in conjunction with the accompanying drawings. The attached drawings are for reference only and are not used to limit the embodiments of the present application. In the following technical description, for the convenience of explanation, a full understanding of the disclosed embodiments is provided through multiple details. However, one or more embodiments can still be implemented without these details. In other cases, to simplify the drawings, well-known structures and devices can be simplified for display.
[0033] The terms "first", "second", etc. in the specification and claims of the embodiments of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the embodiments of the present application described here. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions.
[0034] Unless otherwise stated, the term "plurality" means two or more.
[0035] The term "correspondence" may refer to an association relationship or a binding relationship. The correspondence between A and B means that there is an association relationship or a binding relationship between A and B.
[0036] Embodiment 1
[0037] The present application provides an audio conversion method. Figure 1 As shown, Figure 1 The flowchart of the audio conversion method provided in the embodiment of the present application includes:
[0038] Step S101, obtaining audio data to be converted and a sampling rate multiplier.
[0039] In some embodiments, the audio data to be converted may be audio data of a preset duration that needs to be converted. Wherein, the preset duration can be set according to the experience of the engineer, for example: 1 second. Exemplarily, assuming that the electronic device is an audio playback device, the audio conversion method of the present application is arranged in the audio playback device, and the audio playback device is connected to the sound pickup device for communication. The sound pickup device is used to receive external voices and convert the external voices into audio data and send them to the audio playback device. Wherein, the sound pickup device converts the external voices picked up within the preset duration into audio to be converted and sends them to the audio playback device at intervals of a preset duration. When the preset duration is set to be small, the external voice picked up by the sound pickup device may not be a complete sentence, but a complete sentence is sent to the audio playback device in sequence as multiple audios to be converted. Since the audio playback device converts the audio to be converted each time it receives the audio to be converted, and since there is connection data between the audio data to be converted and the previous frame of audio data, the audio playback device can achieve smooth real-time conversion.
[0040] In some embodiments, the sampling rate multiplier may be obtained by: obtaining a preset original sampling rate and a preset target sampling rate; and taking the quotient of the target sampling rate and the original sampling rate as the sampling rate multiplier.
[0041] In other embodiments, the sampling rate multiplier preset by the user in the electronic device may also be directly read.
[0042] Exemplarily, the electronic device is provided with an input device, such as a keyboard or a touch screen, etc. The user can input the original sampling rate and the target sampling rate through the input device, and the user can also input the sampling rate multiplier through the input device.
[0043] Step S102, determining the spliced data according to the sampling rate multiplier and the previous frame of audio data of the audio data to be converted.
[0044] The splicing data includes the sampling points to be spliced or the position numbers to be spliced.
[0045] In some embodiments, step S102 may include: determining whether the audio data to be converted is first input data; if the audio data to be converted is not first input data, determining the splicing data according to the sampling rate multiplier and the previous frame of audio data of the audio data to be converted.
[0046] In the above implementation, a first input variable is set in a preset area of the electronic device, and a first preset variable value is assigned to the first input variable; after the electronic device receives the audio data to be converted, the first input variable is assigned to the second preset variable value. Determining whether the audio data to be converted is the first input data may be to read the first input variable before receiving the audio data to be converted, and when the first input variable is the first preset variable value, determining that the audio data to be converted is the first input data.
[0047] Exemplarily, the sound pickup device sends the audio data to be converted to the electronic device. Before receiving the audio data to be converted, the electronic device first reads the first input variable and determines whether the audio data to be converted is the first input data, and then receives the audio data to be converted sent by the sound pickup device.
[0048] In the above-mentioned embodiment, the splicing data is determined according to the sampling rate multiplier and the previous frame of audio data of the audio data to be converted, including: when the sampling rate multiplier represents an increase in the sampling rate, a sampling point at the end of the previous frame of audio data of the audio data to be converted is used as the sampling point to be spliced; and / or, when the sampling rate multiplier represents a decrease in the sampling rate, the data amount of the previous frame of audio data of the audio data to be converted is obtained; the remainder is obtained by taking the remainder of the reciprocal of the sampling rate multiplier using the data amount; and the remainder is determined as the serial number of the position to be spliced.
[0049] In the above embodiment, when the sampling rate multiplier is greater than 1, the sampling rate multiplier represents an increase in the sampling rate. When the sampling rate multiplier is between 0-1, the sampling rate multiplier represents a decrease in the sampling rate. In this way, since when the sampling rate multiplier is greater than 1, it means that the new sampling rate is higher than the original sampling rate, thus when the sampling rate multiplier is greater than 1, the sampling rate multiplier represents an increase in the sampling rate. Similarly, when the sampling rate multiplier is between 0-1, it means that the new sampling rate is lower than the original sampling rate, thus when the sampling rate multiplier is between 0-1, the sampling rate multiplier represents a decrease in the sampling rate.
[0050] For example, there are multiple sampling points in the previous frame of audio data, and in the order of the time of audio acquisition, the sampling points are, for example, sampling point a, sampling point b, sampling point c, sampling point d, and sampling point e. Then, sampling point e is a sampling point at the end of the previous frame of audio data. Assuming the remainder is 2, the sequence number of the position to be spliced is 2.
[0051] Step S103, determining the audio data to be connected according to the spliced data and the audio data to be converted.
[0052] In some embodiments, the spliced data includes sampling points to be spliced, and step S103 may include: splicing the sampling points to be spliced into the audio data to be converted according to the time sequence of obtaining the audio, to obtain the audio data to be connected.
[0053] Exemplarily, there are multiple sampling points in the previous frame of audio data, and according to the time sequence of audio acquisition, the sampling points are, for example, sampling point a, sampling point b, sampling point c, sampling point d, and sampling point e. Among them, the sampling point to be spliced is sampling point e. There are multiple sampling points in the audio to be converted, and according to the time sequence of audio acquisition, the sampling points are, for example, sampling point f, sampling point g, and sampling point h. Then, the sampling points of the audio data to be connected are, for example, sampling point e, sampling point f, sampling point g, and sampling point h.
[0054] In some embodiments, the spliced data includes a sequence number of a position to be spliced, and step S103 may include: splicing a sampling point located at a preset number of bits in the previous frame of audio data to be converted into the audio data to be connected according to the time sequence of acquiring the audio, to obtain the audio data to be connected; the preset number of bits is equal to the sequence number of the position to be spliced.
[0055] In some other embodiments, the splicing data includes the sequence number of the position to be spliced, and step S103 may include: calculating the inverse of the magnification minus the sequence number of the position to be spliced to obtain the offset position sequence number. All sampling points after the offset position sequence number in the audio data to be converted are used as the audio data to be connected.
[0056] It can be understood that the sampling points in the audio data to be converted are sorted according to the time sequence of obtaining the audio. For example, according to the time sequence of obtaining the audio, the position sequence number of the first sampling point in the audio data to be converted is 1, and the position sequence number of the second sampling point in the audio data to be converted is 2. The sampling points in the audio data to be connected are sorted according to the time sequence of obtaining the audio. For example, according to the time sequence of obtaining the audio, the position sequence number of the third sampling point in the audio data to be connected is 3.
[0057] In the above embodiment, correspondingly, converting the audio data to be connected according to the sampling rate multiplier to obtain the first target audio data can be: by calculating PCM"r=PCMI(r×(1 / m)), the second target sampling point is obtained; the sampling points at the offset position in the audio data to be converted and each second target sampling point form the first target audio data. It can be understood that the order of the sampling points at the offset position in the audio data to be converted in the first target audio data is located before each second target sampling point.
[0058] Wherein, PCM"r is the rth first target sampling point; PCMI(r×(1 / m)) is the 1 / m×rth sampling point in the audio data to be connected; r=0, ...p; the value of p is equal to the total number of sampling points of the audio data to be connected multiplied by the sampling rate multiplier; m is the sampling rate multiplier. It can be understood that the 1 / m×rth sampling point is the sampling point with a position number of 1 / m×r.
[0059] Exemplarily, assuming that the position number to be spliced is 2, the inverse of the magnification is 5, and the offset position number is 3. The sampling points corresponding to the position numbers 4 and greater than the position number 4 in the audio data to be converted are used as the audio data to be connected. The audio data to be connected consisting of the sampling points corresponding to the position numbers 4 and greater than the position number 4 is converted according to the sampling magnification to obtain each second target sampling point. The sampling point of the position number 3 in the audio data to be converted and each second target sampling point form the first target audio data.
[0060] Step S104, converting the audio data to be connected according to the sampling rate multiplier to obtain the first target audio data.
[0061] In some embodiments, converting the audio data to be connected according to the sampling rate multiplier to obtain the first target audio data includes: when the sampling rate multiplier represents an increase in the sampling rate, for every two consecutive sampling points in the audio data to be connected, obtaining the first target sampling point by calculating PCM'n=PCM1×﹙﹙m-n﹚÷m﹚+PCM2×﹙n÷m﹚; each first target sampling point forms the first target audio data; and / or, when the sampling rate multiplier represents a decrease in the sampling rate, obtaining the second target sampling point by calculating PCM"r=PCMI(r×(1 / m)); each second target sampling point forms the first target audio data.
[0062] Among them, PCM'n is the nth first target sampling point of two consecutive sampling points; PCM1 is one sampling point of two consecutive sampling points; PCM2 is the other sampling point of two consecutive sampling points; n=0, ...m; m is the sampling rate multiplier; PCM"r is the rth first target sampling point; PCMI(r×(1 / m)) is the 1 / m×rth sampling point in the audio data to be connected; r=0, ...p; the value of p is equal to the total number of sampling points of the audio data to be connected multiplied by the sampling rate multiplier.
[0063] In some embodiments, if the audio data to be converted is in G711A coding format, the audio data to be connected determined based on the spliced data and the audio data to be converted is also in G711A coding format. The audio data to be connected in G711A coding format is converted into audio data to be connected in PCM (Pulse Code Modulation) coding format to obtain format-converted audio data.
[0064] The audio data to be connected is converted according to the sampling rate multiple, that is, the format-converted audio data corresponding to the audio data to be connected is converted according to the sampling rate multiple. Every two consecutive sampling points in the audio data to be connected can be: every two consecutive sampling points in the format-converted audio data.
[0065] Correspondingly, each first target sampling point forms the first target audio data can be: each first target sampling point forms the first candidate audio data, the first candidate audio data in PCM encoding format is converted into the first candidate audio data in G711A encoding format, and the first candidate audio data after the conversion is used as the first target audio data.
[0066] In the above embodiment, the audio coding conversion logic in the G711 open source library can be used to implement the conversion of audio data in the PCM coding format into audio data in the G711A coding format, and the audio coding conversion logic in the G711 open source library can also be used to implement the conversion of audio data in the G711A coding format into audio data in the PCM coding format. Of course, engineers can also choose other methods in the prior art that can realize the conversion between the G711A coding format and the PCM coding format, which is not limited here.
[0067] Exemplarily, converting the first candidate audio data in PCM encoding format into the first candidate audio data in G711A encoding format may be as follows: obtaining the numerical value of each sampling point of the first candidate audio data in PCM encoding format. According to the numerical mapping relationship between the preset PCM encoding format and the G711A encoding format, the PCM encoding format is converted into the G711A encoding format. In this way, by converting the data in the G711A encoding format into the corresponding PCM encoding format, the sampling points to be added are calculated in the PCM encoding format, and then when it is converted into the G711A encoding format, since the accuracy of the G711A encoding format used is sufficient in the environment of use, the output sound effect will not be reduced. The above method can reduce the amount of data without affecting the user experience and save the Flash size occupied by the program.
[0068] In some embodiments, after determining whether the audio data to be converted is first input data, the audio conversion method further includes: if the audio data to be converted is first input data, converting the audio data to be converted according to a sampling rate multiplier to obtain second target audio data.
[0069] In the above embodiment, converting the audio data to be converted according to the sampling rate multiplier to obtain the second target audio data can be: when the sampling rate multiplier represents an increase in the sampling rate, for every two consecutive sampling points in the audio data to be converted, by calculating PCM'n=PCM1×﹙﹙m-n﹚÷m﹚+PCM2×﹙n÷m﹚, a third target sampling point is obtained; each third target sampling point forms the second target audio data; and / or, when the sampling rate multiplier represents a decrease in the sampling rate, by calculating PCM"r=PCMI(r×(1 / m)), a fourth target sampling point is obtained, and each fourth target sampling point forms the second target audio data.
[0070] Wherein, in the case where the sampling rate multiplier represents the sampling rate increase, if the audio data to be converted is the first input data, the audio data to be converted does not need to be connected with the previous frame of audio data, and the last sampling point of the audio data to be converted will participate in the audio conversion of the next frame of audio data. Thus, in order to be equal to the amount of data after the conversion of other audio data, in one embodiment, before the audio data to be converted is converted, a sampling point with a value of 0xd5 can be added to the starting position of the audio data to be converted to form new audio data to be converted, and then the audio data to be converted with the added sampling point is converted according to the sampling rate multiplier to obtain the second target audio data. In another embodiment, the audio data to be converted can be directly converted according to the sampling rate multiplier to obtain the third target sampling point, and m-1 sampling points with a value of 0xd5 are added to the starting position of the third target sampling point, and the added sampling points and the third target sampling points are used together as the second target audio data. Wherein, the sampling point with a value of 0xd5 represents the silent data of G711A.
[0071] In some embodiments, after obtaining the audio data to be converted and the sampling rate multiplier, the audio conversion method may further include: when the sampling rate multiplier represents an increase in the sampling rate, obtaining the last sampling point of the audio data to be converted, and recording the value of the sampling point to a first preset position; when the sampling rate multiplier represents a decrease in the sampling rate, obtaining the data amount of the audio data to be converted, and recording the data amount to a second preset position.
[0072] In some embodiments, the data packet size of the audio data to be converted can also be determined according to the data volume, which includes determining the data packet size by multiplying the data volume by the sampling rate multiplier when the sampling rate multiplier represents a decrease in the sampling rate. It can be understood that the data packet size is the number of sampling points of the first target audio data converted from the audio data to be converted.
[0073] Exemplarily, the data volume of the audio data to be converted is obtained, for example: 16K sampling points, the sampling rate multiplier is 1 / 2, and the data packet size is 8K sampling points.
[0074] In some embodiments, the audio conversion method is run by creating an instance, and after multiple segments of audio data to be converted included in a complete speech are converted according to the sampling rate multiple, the data recorded in the instance is cleared.
[0075] Exemplary, combined Figure 2 As shown, another audio conversion method is provided in an embodiment of the present application, including:
[0076] Step S201, creating an instance.
[0077] Step S202, calling the instance creation interface, and inputting the original sampling rate and the target sampling rate.
[0078] Step S203, determining and recording the sampling rate multiplier according to the original sampling rate and the target sampling rate.
[0079] Step S204, calling a preset sampling rate conversion interface, and filling the audio data to be converted into the instance.
[0080] Step S205, determining whether the sampling rate multiplier represents a sampling rate increase. If the sampling rate multiplier represents a sampling rate increase, executing step S206; if the sampling rate multiplier does not represent a sampling rate increase, executing step S209.
[0081] Step S206, determining whether the audio data to be converted is the first input data. If the audio data to be converted is the first input data, executing step S207. If the audio data to be converted is not the first input data, executing step S208.
[0082] Step S207, convert the audio data to be converted according to the sampling rate multiplier to obtain the third target sampling point; add m-1 sampling points with a value of 0xd5 at the beginning position of the third target sampling point, and use the added sampling points and the third target sampling point together as the second target audio data.
[0083] Step S208: taking a sampling point at the end of the previous frame of audio data to be converted as a sampling point to be spliced.
[0084] Step S209, determining whether the audio data to be converted is input data for the first time. If the audio data to be converted is input data for the first time, executing step S210. If the audio data to be converted is not input data for the first time, executing step S211.
[0085] Step S210, obtaining the data volume of the audio data to be converted; and recording the data volume to a second preset location.
[0086] Step S211, obtaining the data volume of the previous frame of audio data to be converted; taking the modulus of the reciprocal of the sampling rate multiplier using the data volume; and determining the remainder as the sequence number of the position to be spliced.
[0087] Step S212, determining the audio data to be connected according to the spliced data and the audio data to be converted.
[0088] Step S213, converting the audio data to be connected according to the sampling rate multiplier to obtain the first target audio data.
[0089] Step S214, in response to a clear instruction from the user, clear the data in the instance.
[0090] Embodiment 2
[0091] Based on the same inventive concept, the present application embodiment provides an audio conversion device, such as Figure 3 As shown, the audio conversion device includes: an acquisition module 1, a splicing data determination module 2, a to-be-connected audio determination module 3 and a conversion module 4. Among them, the acquisition module 1 is used to acquire the audio data to be converted and the sampling rate multiple; the splicing data determination module 2 is used to determine the splicing data according to the sampling rate multiple and the previous frame of audio data of the audio data to be converted, and the splicing data includes the sampling point to be spliced or the sequence number of the position to be spliced; the to-be-connected audio determination module 3 is used to determine the to-be-connected audio data according to the splicing data and the to-be-converted audio data; the conversion module 4 is used to convert the to-be-connected audio data according to the sampling rate multiple to obtain the first target audio data.
[0092] Optionally, the acquisition module 1 is used to acquire the sampling rate multiplier in the following manner: acquiring a preset original sampling rate and a preset target sampling rate; and taking the quotient of the target sampling rate and the original sampling rate as the sampling rate multiplier.
[0093] Optionally, the splicing data determination module 2 is used to determine the splicing data according to the sampling rate multiplier and the previous frame of audio data of the audio data to be converted in the following manner: when the sampling rate multiplier represents an increase in the sampling rate, a sampling point at the end of the previous frame of audio data of the audio data to be converted is used as the sampling point to be spliced; and / or, when the sampling rate multiplier represents a decrease in the sampling rate, the data amount of the previous frame of audio data of the audio data to be converted is obtained; the data amount is used to take the remainder of the inverse of the sampling rate multiplier to obtain the remainder; and the remainder is determined as the serial number of the position to be spliced.
[0094] Optionally, the conversion module 4 is used to convert the audio data to be connected according to the sampling rate multiplier in the following manner to obtain the first target audio data: when the sampling rate multiplier represents the sampling rate increase, for every two consecutive sampling points in the audio data to be connected, the first target sampling point is obtained by calculating PCM'n=PCM1×﹙﹙m-n﹚÷m﹚+PCM2×﹙n÷m﹚; each first target sampling point forms the first target audio data; wherein PCM'n is the nth first target sampling point of the two consecutive sampling points; PCM1 is one of the two consecutive sampling points; PCM'n is the nth first target sampling point of the two consecutive sampling points; PCM1 is one of the two consecutive sampling points; PCM'n is the nth first target sampling point of the two consecutive sampling points; PCM1 is the nth first target sampling point of the two consecutive sampling points; PCM2 ... CM2 is another sampling point of two consecutive sampling points; n=0, ...m; m is the sampling rate multiplier; and / or, when the sampling rate multiplier represents a decrease in the sampling rate, the second target sampling point is obtained by calculating PCM"r=PCMI(r×(1 / m)), and each second target sampling point forms the first target audio data; wherein PCM"r is the rth first target sampling point; PCMI(r×(1 / m)) is the 1 / m×rth sampling point in the audio data to be connected; r=0, ...p; the value of p is equal to the total number of sampling points of the audio data to be connected multiplied by the sampling rate multiplier.
[0095] Optionally, the splicing data determination module 2 is used to determine the splicing data according to the sampling rate multiplier and the previous frame of audio data to be converted in the following manner: judging whether the audio data to be converted is the first input data; if the audio data to be converted is not the first input data, determining the splicing data according to the sampling rate multiplier and the previous frame of audio data to be converted.
[0096] Optionally, the audio conversion device further includes a conversion module for determining whether the audio data to be converted is first input data, and if the audio data to be converted is first input data, converting the audio data to be converted according to a sampling rate multiplier to obtain second target audio data.
[0097] Optionally, the audio conversion device also includes a data storage module, which is used to obtain the audio data to be converted and the sampling rate multiplier, and when the sampling rate multiplier indicates an increase in the sampling rate, obtain the last sampling point of the audio data to be converted and record the value of the sampling point to a first preset position; when the sampling rate multiplier indicates a decrease in the sampling rate, obtain the data amount of the audio data to be converted and record the data amount to a second preset position.
[0098] It can be understood that the various embodiments described in the first embodiment are also applicable to the second embodiment if there is no conflict. Based on the consideration of brevity of description, they will not be repeated here.
[0099] Embodiment 3
[0100] Combination Figure 4As shown, an embodiment of the present application provides an electronic device, including a processor 5 and a memory 7. Optionally, the device may also include a communication interface 8 and a bus 6. The processor 5, the communication interface 8, and the memory 7 may communicate with each other through the bus 6. The communication interface 8 may be used for information transmission. The processor 5 may call the logic instructions in the memory 7 to execute the audio conversion method of the above embodiment.
[0101] In addition, the logic instructions in the above-mentioned memory 7 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.
[0102] The memory 7 is a computer-readable storage medium that can be used to store software programs and computer executable programs, such as program instructions / modules corresponding to the method in the embodiment of the present application. The processor 5 executes the function application and data processing by running the program instructions / modules stored in the memory 7, that is, the audio conversion method in the above embodiment is implemented.
[0103] The memory 7 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 7 may include a high-speed random access memory and may also include a non-volatile memory.
[0104] The electronic device may be a computer or a server, etc.
[0105] An embodiment of the present application provides a storage medium storing computer executable instructions, wherein the computer executable instructions are configured to execute the above-mentioned audio conversion method.
[0106] An embodiment of the present application provides a computer program product, which includes a computer program stored on a storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer executes the above-mentioned audio conversion method.
[0107] The computer-readable storage medium mentioned above may be a transient computer-readable storage medium or a non-transitory computer-readable storage medium.
[0108] The technical solution of the embodiment of the present application can be embodied in the form of a software product, which is stored in a storage medium and includes one or more instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in the embodiment of the present application. The aforementioned storage medium can be a non-transient storage medium, including: a USB flash drive, a mobile hard disk, a read-only memory, a random access memory, a magnetic disk or an optical disk, etc., which can store program codes, or a transient storage medium.
[0109] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. 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.
[0110] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application. At the same time, the above embodiments can be combined with each other to form new embodiments without conflict.
Claims
1. An audio conversion method, characterized in that: include: Get the audio data to be converted and the sampling rate multiplier; Determine the splicing data according to the sampling rate multiplier and the previous frame of audio data of the audio data to be converted, wherein the splicing data includes the sampling point to be spliced or the position number to be spliced; Determine the audio data to be connected according to the spliced data and the audio data to be converted; The audio data to be connected is converted according to the sampling rate multiplier to obtain first target audio data.
2. The method according to claim 1, characterized in that: The sampling rate multiplier is obtained in the following way: Get the preset original sampling rate and the preset target sampling rate; The quotient of the target sampling rate and the original sampling rate is taken as the sampling rate multiplier.
3. The method according to claim 1, characterized in that Determining the spliced data according to the sampling rate multiplier and the previous frame of audio data of the audio data to be converted includes: In the case where the sampling rate multiplier represents a sampling rate increase, a sampling point at the end of a previous frame of audio data to be converted is used as a sampling point to be spliced; and / or, When the sampling rate multiplier represents a decrease in the sampling rate, the data volume of the previous frame of audio data of the audio data to be converted is obtained; the remainder is obtained by taking the modulus of the reciprocal of the sampling rate multiplier using the data volume; and the remainder is determined as the sequence number of the position to be spliced.
4. The method according to claim 1, characterized in that: Converting the audio data to be connected according to the sampling rate multiplier to obtain first target audio data includes: In the case where the sampling rate multiplier represents the sampling rate increase, for every two consecutive sampling points in the audio data to be connected, the first target sampling point is obtained by calculating PCM'n=PCM1×﹙﹙m-n﹚÷m﹚+PCM2×﹙n÷m﹚; each of the first target sampling points forms the first target audio data; wherein, PCM'n is the nth first target sampling point of two consecutive sampling points; PCM1 is one sampling point of the two consecutive sampling points; PCM2 is the other sampling point of the two consecutive sampling points; n=0, ...m; m is the sampling rate multiplier; and / or, In the case where the sampling rate multiplier represents a decrease in the sampling rate, the second target sampling points are obtained by calculating PCM"r=PCMI(r×(1 / m)), and each of the second target sampling points forms the first target audio data; wherein PCM"r is the rth first target sampling point; PCMI(r×(1 / m)) is the 1 / m×rth sampling point in the audio data to be connected; r=0, ...p; the value of p is equal to the total number of sampling points of the audio data to be connected multiplied by the sampling rate multiplier; m is the sampling rate multiplier.
5. The method according to any one of claims 1 to 4, characterized in that: Determining the spliced data according to the sampling rate multiplier and the previous frame of audio data of the audio data to be converted includes: Determining whether the audio data to be converted is first input data; In a case where the audio data to be converted is not the first input data, the splicing data is determined according to the sampling rate multiplier and the previous frame of audio data of the audio data to be converted.
6. The method according to claim 5, characterized in that After determining whether the audio data to be converted is first input data, the method further includes: In a case where the audio data to be converted is first input data, the audio data to be converted is converted according to the sampling rate multiplier to obtain second target audio data.
7. The method according to any one of claims 1 to 4, characterized in that: After obtaining the audio data to be converted and the sampling rate multiplier, the method further includes: In the case where the sampling rate multiplier represents a sampling rate increase, obtaining a sampling point at the end of the audio data to be converted, and recording the value of the sampling point to a first preset position; In the case where the sampling rate multiplier represents a decrease in the sampling rate, the data amount of the audio data to be converted is obtained, and the data amount is recorded in a second preset position.
8. An audio conversion device, characterized in that: include: An acquisition module is used to obtain the audio data to be converted and the sampling rate multiplier; A splicing data determination module, used to determine the splicing data according to the sampling rate multiplier and the previous frame of audio data of the audio data to be converted, wherein the splicing data includes the sampling point to be spliced or the position number to be spliced; An audio data to be connected determining module, used for determining the audio data to be connected according to the spliced data and the audio data to be converted; The conversion module is used to convert the audio data to be connected according to the sampling rate multiplier to obtain the first target audio data.
9. An electronic device, characterized in that: It comprises 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 audio conversion method according to any one of claims 1 to 7.
10. A storage medium, characterized in that: The storage medium stores computer executable instructions, and when the computer executable instructions are called and executed by the processor, the computer executable instructions enable the processor to implement the audio conversion method according to any one of claims 1 to 7.
