An audio variable speed playing method and device, electronic equipment and medium
By using the target audio tool in the WASM module to perform audio speed adjustment, the sound distortion problem when changing the audio speed in web browsers was solved, achieving a playback effect that does not change pitch and accurate progress display.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-14
- Publication Date
- 2026-03-31
AI Technical Summary
Web browsers are prone to audio distortion when playing audio at varying speeds, especially when adjusting the playback rate, which can cause the audio to become pitch-distorted.
Audio speed processing is performed using the target audio tool in the WebAssembly (WASM) module. The speed is adjusted by matching the data type of the target sampling bit depth, thus avoiding the need to adjust the playback speed of the audio node in the browser and preventing sound distortion.
It achieves the effect of changing the audio speed without changing the pitch, avoids noise problems caused by mismatched sampling bit depth, and accurately displays the audio playback progress.
Smart Images

Figure CN116028008B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more particularly to the field of audio processing technology. Background Technology
[0002] To accommodate users' needs for variable playback speed when playing audio, web browsers can adjust the playback speed by setting a playback rate multiplier. For example, if a user selects 0.5x speed, the web browser will reduce the audio playback speed to 0.5 times the normal playback speed; if the user selects 2x speed, the web browser will increase the playback speed to twice the normal playback speed. Summary of the Invention
[0003] This disclosure provides an audio speed-adjusting playback method, apparatus, electronic device, and medium.
[0004] According to a first aspect of this disclosure, an audio speed-adjustable playback method is provided, comprising:
[0005] Receive an audio speed adjustment request, the audio speed adjustment request being used to request that the playback rate of a specified audio be adjusted to a target rate;
[0006] Input the audio data to be speed-changed and the target sampling bit depth of the specified audio into the WASM module;
[0007] The target audio tool encapsulated in the WASM module is invoked to perform speed-changing processing on the audio data to be changed according to the target rate, thereby obtaining speed-changed audio data; the target audio tool is an audio tool that matches the target sampling bit depth.
[0008] Acquire the variable-speed audio data and play the variable-speed audio data.
[0009] According to a second aspect of this disclosure, an audio speed-adjustable playback device is provided, comprising:
[0010] A receiving module is used to receive an audio speed adjustment request, wherein the audio speed adjustment request is used to request that the playback rate of a specified audio be adjusted to a target rate;
[0011] The input module is used to input the audio data to be speed-changed and the target sampling bit depth of the specified audio into the WASM module;
[0012] The speed-changing module is used to call the target audio tool encapsulated in the WASM module to perform speed-changing processing on the audio data to be changed according to the target rate, so as to obtain speed-changing audio data; the target audio tool is an audio tool that matches the target sampling bit depth;
[0013] The acquisition module is used to acquire the variable speed audio data and play the variable speed audio data.
[0014] According to a third aspect of this disclosure, an electronic device is provided, comprising:
[0015] At least one processor; and
[0016] A memory communicatively connected to the at least one processor; wherein,
[0017] The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method described in the first aspect.
[0018] According to a fourth aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions, wherein the computer instructions are configured to cause the computer to perform the method described in the first aspect.
[0019] According to a fifth aspect of this disclosure, a computer program product is provided, comprising a computer program that, when executed by a processor, implements the method described in the first aspect.
[0020] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description
[0021] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein:
[0022] Figure 1 This is a flowchart of an audio speed-changing playback method provided in an embodiment of this disclosure;
[0023] Figure 2 This is an exemplary flowchart of an audio speed-changing playback method provided in this disclosure embodiment;
[0024] Figure 3 This is a schematic diagram of the structure of an audio speed-changing playback device provided in an embodiment of this disclosure.
[0025] Figure 4 This is a block diagram of an electronic device used to implement the audio speed-changing playback method of the embodiments of this disclosure. Detailed Implementation
[0026] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0027] Web browsers typically use Audio Context to play audio. Audio Context is an audio interface used to represent an audio processing graph constructed from linked Audio Nodes.
[0028] When playing audio using the Audio Context, if you need to adjust the playback speed, you can set the playback rate of the Audio Buffer Source Node. The Audio Buffer Source Node is an audio node that is an audio source that uses an Audio Buffer to cache audio data.
[0029] However, adjusting the playback rate causes audio distortion. For example, the audio frequency is 44100Hz at 1.0x speed, but becomes 88200Hz at 2.0x speed, and 22050Hz at 0.5x speed, resulting in noticeable audio distortion.
[0030] To avoid sound distortion, this disclosure provides an audio speed-adjusting playback method, which is applied to a web application, such as... Figure 1 As shown, the method includes:
[0031] S101. Receive an audio speed adjustment request. The audio speed adjustment request is used to request that the playback rate of the specified audio be adjusted to the target rate.
[0032] Optionally, the audio speed change request can be triggered by the user. For example, when playing audio on a webpage in a browser, the user can select playback speeds such as 0.5x, 1.25x, 1.5x, and 2x on the webpage, thereby triggering the audio speed change request.
[0033] The specified audio is the currently playing audio, and the target rate is the rate selected by the user, such as 1.5x speed.
[0034] S102. Input the audio data to be changed speed and the target sampling bit depth of the specified audio into the WASM module.
[0035] WASM stands for WebAssembly, and it's an encoding format that can run on the web. Web browsers can load WASM files from servers to obtain WASM modules.
[0036] The WASM file contains pitch.c and the sonic tool. pitch.c is C code used to call the sonic tool. The sonic tool is a C-based utility used to implement audio speed adjustment.
[0037] In this embodiment of the disclosure, the pitch.c and sonic code can be pre-compiled into a WASM file using the Emscripten tool, and the WASM file can be stored on a server. As an example, the server can specifically be a Content Delivery Network (CDN) server.
[0038] Optionally, the browser can call the interface exposed by pitch.c in the WASM module and input the audio data to be sped up through the interface. Specifically, it can input a Uint8Array (8-bit unsigned integer array) object, which includes the audio data to be sped up, specifically Pulse Code Modulation (PCM).
[0039] S103. Call the target audio tool encapsulated in the WASM module to perform speed-changing processing on the audio data to be changed according to the target rate, and obtain the speed-changing audio data.
[0040] The web application can call pitch.c from the WASM module, which in turn allows pitch.c to call the target audio tool. The target audio tool is an audio tool that matches the target sampling bit depth, i.e., the target sonic tool.
[0041] The target audio tool can speed-process audio data to be changed according to the target rate and output the changed-speed audio data.
[0042] S104. Obtain variable speed audio data and play the variable speed audio data.
[0043] The web client can output variable-speed audio data to AudioContext, which can then play the audio based on the variable-speed audio data.
[0044] In this embodiment of the present disclosure, upon receiving an audio speed adjustment request, the specified audio data to be adjusted in speed and the target sampling bit depth can be input into the WASM module. Since the web client cannot run C language code, the speed adjustment function of the target audio tool encapsulated in the WASM module can be used indirectly by calling the target audio tool to perform speed adjustment processing on the audio data to be adjusted. Because the speed-adjusted audio data is obtained using the target audio tool and the playback speed of the audio node in the browser is not adjusted, there will be no sound distortion problem. Furthermore, since the target audio tool matches the target sampling bit depth, noise caused by sampling bit depth mismatch can be avoided. Thus, this method can achieve a playback effect of adjusting speed without changing pitch.
[0045] In the above embodiments, the read data type and write data type of the target audio tool are both data types that match the target sampling bit depth, thereby avoiding the target audio tool from using data types that do not match the target sampling bit depth to process the audio data to be changed in speed, and preventing noise from occurring when playing the changed speed audio data.
[0046] If the target sampling bit depth is 8 bits, then the read and write data types of the target audio tool are both unsigned character (UnsignedChar). This is because the data size of the Char type is usually 1 byte, or 8 bits, which matches the 8-bit sampling bit depth.
[0047] In other words, the target audio tool can use the sonicWriteUnsignedCharToStream method to write to the stream and the sonicReadUnsignedCharToStream method to read from the stream.
[0048] The target audio tool can first use the sonicSetSpeed method to set the target speed, then use the sonicWriteUnsignedCharToStream method to write the audio data to be speed-changed to the sonic stream, and finally use the sonicReadUnsignedCharToStream method to read the sonic stream to obtain the speed-changed audio data.
[0049] If the target sampling bit depth is 16 bits, then the read and write data types of the target audio tool are both Short integers. The data size of the Short type is usually 2 bytes, or 16 bits, so it matches the 16-bit sampling bit depth.
[0050] In other words, the target audio tool can use the sonicWriteShortToStream method to write to the stream and the sonicReadShortToStream method to read from the stream.
[0051] If the target sampling bit depth is 32 bits, then the read and write data types of the target audio tool are both floating-point (Float). The data size of the Float type is usually 4 bytes, or 32 bits, so it matches the 32-bit sampling bit depth.
[0052] In other words, the target audio tool can use the sonicWriteFloatToStream method to write to the stream and the sonicReadFloatToStream method to read from the stream.
[0053] Because the length of the data type used by the target audio tool when writing to and reading from the stream matches the target sampling bit depth, it avoids reading the stream with a mismatched data type, which could lead to reading data that does not meet the sampling bit depth and causing playback noise.
[0054] In some embodiments of this disclosure, when transmitting the audio data to be speed-changed to the WASM module, a callback function fn may also be transmitted. Furthermore, after S103, where the target audio tool encapsulated in the WASM module is invoked to perform speed-changing processing on the audio data to be speed-changed according to the target rate, and the speed-changed audio data is obtained, the method further includes:
[0055] Get the callback function returned by the WASM module. The callback function includes the starting buffer position and data size of the variable speed audio data.
[0056] In the WASM module, after the target audio tool completes the speed-changing processing of the audio data, the WASM module can call a callback function to notify the JavaScript on the web side that processing is complete. Furthermore, the callback function can carry the starting buffer position and data size of the speed-changing audio data.
[0057] The starting buffer position refers to the starting buffer position of the variable speed audio data in the WASM module's buffer, and the data size refers to the length of the variable speed audio data.
[0058] Accordingly, S104, acquiring variable speed audio data, can be implemented as follows:
[0059] In response to the callback function, variable speed audio data is read from the memory of the WASM module, starting from the initial buffer position and according to the data size, using a byte-rounding method.
[0060] In this context, the JavaScript on the web can determine the number of bits included in the variable-speed audio data based on the data size and the target sampling bit depth. Then, starting from the initial cache position in the memory of the WASM module, it reads the data according to the number of bits and uses the read data as the variable-speed audio data.
[0061] The number of bits included in the variable speed audio data is the value obtained by rounding the data size to the nearest integer based on the number of sampled bytes, and then multiplying it by the number of sampled bytes.
[0062] That is, the number of bits = parseInt(size / n) * n. Where n is the number of sampled bytes, and n is the ratio of the sample bit depth to 8. size is the data size. parseInt() is a built-in JavaScript function used to parse a string and return an integer with a specified base; in this embodiment, the specified base can be the number of sampled bytes.
[0063] For example, assuming the target sampling bit depth for the specified audio is 16, i.e., 16 bits, then the number of sampled bytes is 2 bytes, meaning 2 bytes of data are sampled each time. If the size is 17 bits, it can be seen that 17 bits is not an integer multiple of the sampling bit depth. This may be because the WASM module ignores the consecutive zeros at the end of the variable speed audio data when returning the data size. The actual data size should be 32 bits, i.e., the calculated number of bits is 32.
[0064] The aforementioned starting buffer position can be represented as buffer. Reading data from the memory of the WASM module can be represented as: "ctx.Module.HEAPU8.slice(buff,(buff+parseInt(size / n)*n))", that is, using the HEAPU8 module to extract data from the memory of the WASM module from buffer to (buff+parseInt(size / n)*n).
[0065] For example, it is possible to extract data from buffer to buffer+32 bits.
[0066] Reading variable-speed audio data by rounding down to the nearest byte can prevent misalignment of the read variable-speed audio data. Furthermore, by obtaining the data size and the target sampling bit depth, the actual number of bits included in the variable-speed audio data can be accurately calculated. Thus, starting from the initial buffer position, the variable-speed audio data can be read according to this number of bits, ensuring that the complete audio data is read. This avoids playback problems caused by reading misaligned audio data.
[0067] In some embodiments of this disclosure, the callback function obtained by the web client also includes the original timestamp corresponding to the variable speed audio data. Therefore, during the playback of the variable speed audio data, the playback progress of the variable speed audio data can be displayed according to the original timestamp corresponding to the variable speed audio data.
[0068] The original timestamp is the timestamp corresponding to the audio data to be speed-changed. For example, if the audio data to be speed-changed is the audio data from 10:10:00 to 10:11:20 in the specified audio, that is, the playback time of this audio data at normal speed is 20 seconds.
[0069] If the audio data is sped up at 2x speed, the actual playback duration corresponding to the sped-up audio data is 10 seconds. In this embodiment, the original timestamp corresponding to the sped-up audio data, i.e., 10:10:00 to 10:11:20, can still be obtained. Thus, when playing the audio at double speed, the actual timestamp of this audio can still be displayed, which is equivalent to adding 2 seconds to the timestamp for every 1 second of video played.
[0070] Since the playback rate of AudioContext remains unchanged, AudioContext will treat variable-speed audio data as video at normal speed and play it accordingly. When AudioContext displays the playback progress, it will also display it according to physical time, that is, the timestamp displayed will be incremented by 1 every second.
[0071] However, the variable-speed audio data is actually processed, and the audio content played per second is not 1 second. To accurately display the timestamps, the web application can instead of displaying the timestamps calculated by AudioContext, obtain the timestamps calculated by AudioContext, calculate the actual timestamps to be displayed based on the original timestamps and the target rate corresponding to the variable-speed audio data, and then display the playback progress according to the actual timestamps.
[0072] Using this method, even when playing audio according to variable speed audio data, a timestamp matching the audio content can still be displayed, allowing users to accurately understand the actual playback progress of the audio.
[0073] The following combination Figure 2 The execution flow of the embodiments of this disclosure will be described, such as... Figure 2 As shown, after a user opens a webpage in their browser, the web client loads the audio content and the WASM file.
[0074] It is understandable that the loaded audio content is the audio content that the browser webpage needs to play.
[0075] When the system detects that a user has pressed a button on the webpage to change the playback speed, it transmits the audio data of the next audio segment, the bit depth of the audio data, the target bit rate, the timestamp of the audio segment, and a callback function to the WASM module.
[0076] Furthermore, the pitch.c file in the WASM module can determine the number of sampling bits.
[0077] If the sampling bit depth is 8 bits, use the sonicWriteUnsignedCharToStream method to write to the stream and the sonicReadUnsignedCharToStream method to read from the stream.
[0078] If the sampling bit depth is 16 bits, use the sonicWriteShortToStream method to write to the stream and the sonicReadShortToStream method to read from the stream.
[0079] If the sampling bit depth is 32 bits, use the sonicWriteFloatToStream method to write to the stream and the sonicReadFloatToStream method to read from the stream.
[0080] After completing the speed adjustment of the audio data, a callback function can be called to notify JavaScript that processing is complete. This callback function includes the starting buffer location and data size, and may also include the target bitrate and the original timestamp of the adjusted audio data.
[0081] JavaScript can then read the speed-processed audio data in HEAPU8 format from the cache.
[0082] During the reading process, the number of sampled bytes n can be calculated first.
[0083] Then, the speed-processed audio data is read in byte-aligned manner, and the speed-processed data is submitted to the AudioContext. The AudioContext then plays the speed-processed audio data, and the user can hear audio that changes speed without changing pitch.
[0084] Corresponding to the above method embodiments, this disclosure also provides an audio speed-changing playback device, such as... Figure 3 As shown, the device includes:
[0085] The receiving module 301 is used to receive an audio speed change request, wherein the audio speed change request is used to request that the playback rate of a specified audio be adjusted to a target rate.
[0086] Input module 302 is used to input the audio data to be speed-changed and the target sampling bit depth of the specified audio into the WASM module;
[0087] The speed-changing module 303 is used to call the target audio tool encapsulated in the WASM module to perform speed-changing processing on the audio data to be changed according to the target rate, so as to obtain speed-changing audio data; the target audio tool is an audio tool that matches the target sampling bit depth;
[0088] The acquisition module 304 is used to acquire the variable speed audio data and play the variable speed audio data.
[0089] In this embodiment of the disclosure, the acquisition module 304 is further configured to acquire the callback function returned by the WASM module, wherein the callback function includes the starting buffer position and data size of the variable speed audio data;
[0090] The acquisition module 304 is specifically used to respond to the callback function by reading the variable speed audio data from the memory of the WASM module, starting from the starting cache position and according to the data size, using a byte-rounding method.
[0091] In this embodiment of the disclosure, the acquisition module 304 is specifically used for:
[0092] The number of bits included in the variable speed audio data is determined based on the data size and the target sampling bit depth;
[0093] Starting from the initial cache location in the memory of the WASM module, data is read according to the number of bits, and the read data is used as the variable speed audio data.
[0094] In this embodiment of the disclosure, the callback function further includes the original timestamp corresponding to the variable speed audio data; the device further includes:
[0095] The display module is used to display the playback progress of the variable-speed audio data according to the original timestamp corresponding to the variable-speed audio data during the playback process.
[0096] In the embodiments of this disclosure, the read data type and write data type of the target audio tool are both data types that match the target sampling bit depth.
[0097] In this embodiment of the disclosure, if the target sampling bit depth is 8 bits, then the read data type and write data type of the target audio tool are both unsigned character type;
[0098] If the target sampling bit depth is 16 bits, then the read data type and write data type of the target audio tool are both short integers;
[0099] If the target sampling bit depth is 32 bits, then the read data type and write data type of the target audio tool are both floating-point types.
[0100] The collection, storage, use, processing, transmission, provision, and disclosure of user personal information involved in the technical solution disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0101] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.
[0102] Figure 4 A schematic block diagram of an example electronic device 400 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0103] like Figure 4 As shown, device 400 includes a computing unit 401, which can perform various appropriate actions and processes based on a computer program stored in read-only memory (ROM) 402 or a computer program loaded from storage unit 408 into random access memory (RAM) 403. RAM 403 may also store various programs and data required for the operation of device 400. The computing unit 401, ROM 402, and RAM 403 are interconnected via bus 404. Input / output (I / O) interface 405 is also connected to bus 404.
[0104] Multiple components in device 400 are connected to I / O interface 405, including: input unit 406, such as keyboard, mouse, etc.; output unit 407, such as various types of monitors, speakers, etc.; storage unit 408, such as disk, optical disk, etc.; and communication unit 409, such as network card, modem, wireless transceiver, etc. Communication unit 409 allows device 400 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0105] The computing unit 401 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 401 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 401 performs the various methods and processes described above, such as the audio speed-changing playback method. For example, in some embodiments, the audio speed-changing playback method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 408. In some embodiments, part or all of the computer program may be loaded and / or installed on device 400 via ROM 402 and / or communication unit 409. When the computer program is loaded into RAM 403 and executed by the computing unit 401, one or more steps of the audio speed-changing playback method described above may be performed. Alternatively, in other embodiments, the computing unit 401 may be configured to perform the audio speed-changing playback method by any other suitable means (e.g., by means of firmware).
[0106] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0107] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0108] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0109] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0110] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with embodiments of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.
[0111] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.
[0112] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.
[0113] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.
Claims
1. An audio variable speed playing method, comprising: receiving an audio variable speed request, the audio variable speed request being used to request to adjust a playing speed of specified audio to a target speed; inputting, into a WASM module, to-be-variable-speed-audio data included in the specified audio and a target sample bit number of the specified audio; calling a target audio tool encapsulated in the WASM module to perform variable speed processing on the to-be-variable-speed-audio data according to the target speed, to obtain variable speed audio data; the target audio tool is an audio tool matching the target sample bit number; obtaining a callback function returned by the WASM module, the callback function including a start cache position and a data size of the variable speed audio data; in response to the callback function, determining a bit number included in the variable speed audio data based on the data size and the target sample bit number, reading data from the start cache position in a memory of the WASM module according to the bit number, and taking the read data as the variable speed audio data; playing the variable speed audio data.
2. The method of claim 1, wherein, The callback function further includes an original timestamp corresponding to the variable speed audio data; and the method further comprises: displaying a playing progress of the variable speed audio data according to the original timestamp corresponding to the variable speed audio data during playing of the variable speed audio data.
3. The method of claim 1, wherein, The read data type and the write data type of the target audio tool are both data types matching the target sample bit number.
4. The method of claim 3, wherein, if the target sample bit number is 8 bits, the read data type and the write data type of the target audio tool are both unsigned character types; if the target sample bit number is 16 bits, the read data type and the write data type of the target audio tool are both short integer types; if the target sample bit number is 32 bits, the read data type and the write data type of the target audio tool are both floating point types.
5. An audio variable speed playing apparatus, comprising: a receiving module configured to receive an audio variable speed request, the audio variable speed request being used to request to adjust a playing speed of specified audio to a target speed; an input module configured to input, into a WASM module, to-be-variable-speed-audio data included in the specified audio and a target sample bit number of the specified audio; a variable speed module configured to call a target audio tool encapsulated in the WASM module to perform variable speed processing on the to-be-variable-speed-audio data according to the target speed, to obtain variable speed audio data; the target audio tool is an audio tool matching the target sample bit number; an obtaining module configured to obtain a callback function returned by the WASM module, the callback function including a start cache position and a data size of the variable speed audio data; the obtaining module is further configured to, in response to the callback function, determine a bit number included in the variable speed audio data based on the data size and the target sample bit number, read data from the start cache position in a memory of the WASM module according to the bit number, take the read data as the variable speed audio data, and play the variable speed audio data.
6. The apparatus of claim 5, wherein, The callback function further includes a raw timestamp corresponding to the variable-speed audio data; and the device further includes: a display module configured to display a playing progress of the variable-speed audio data according to the raw timestamp corresponding to the variable-speed audio data during playing of the variable-speed audio data.
7. The apparatus of claim 5, wherein, The read data type and the write data type of the target audio tool are both data types matching the target sampling bit number. 8.The apparatus of claim 7, wherein, if the target sampling bit number is 8 bits, the read data type and the write data type of the target audio tool are both unsigned character types; if the target sampling bit number is 16 bits, the read data type and the write data type of the target audio tool are both short integer types; if the target sampling bit number is 32 bits, the read data type and the write data type of the target audio tool are both floating point types. 9.An electronic device, comprising: at least one processor; and a memory connected to the at least one processor in communication; wherein, the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-4.
10. A non-transitory computer readable storage medium having stored thereon computer instructions, wherein, The computer instructions are used to enable the computer to perform the method of any one of claims 1-4. 11.A computer program product comprising a computer program which, when executed by a processor, implements the method of any one of claims 1-4.
Citation Information
Patent Citations
Method and system for achieving audio and video synchronous speed variation
CN105208426A
Audio recording method, electronic equipment, medium and program product
CN113643728A