Skip to main content

Audio resources

The IDE supports the use of sound clips. 1) First of all, when creating a project, choose a suitable audio sample rate such as 10.2KHz. Theoretically, the higher the sampling rate, the better the quality of the sound and the larger the saved audio data. The human ear hearing frequency is basically 20Hz~20KHz, in order to restore the discrete signal, according to Nyquist sampling theorem need to set the sampling frequency to more than 40KHz. However, in practical applications, the sampling frequency can be appropriately reduced under the condition of satisfying the sound quality in order to reduce the occupied resources.


2) In the UI project, select the "Resources" tab, upload the required image materials and audio files (only mp3 format is supported). Please note that the total size of all resources in a project is up to 100MB.


3) At the bottom of the "Resources" tab, click the "Add New Sound" button.


Click to open the "Sound Configuration" dialog box, where you can edit the "Sound Name"; set the "Sound Serial Number"; if you choose the "Sound Source", then you can select the desired sound from the bottom. If you choose "Sound File", then you can select the desired audio file at the bottom. If you choose "Frequency Ripple" for the sound source, then you can enter to set the "Sound Frequency", "Sound Length", "Sound Length", "Sound Length", "Sound Length", "Sound Length", "Sound Length", "Sound Length", "Sound Length", and so on. If you choose "Frequency Ripple" for the sound source, then you can enter the setting of "Sound Frequency", "Sound Length" and can play the preview; if you don't turn on "Loop", then you will only play it once. If you turn on "Loop", it will play in a loop.


4) Create a new variable, e.g. "Play", register number 1005, initial value 0.


5) Add a layer control in the view to load the background image. Add a button control to set the audio playback function. For the button control, select "On/Off Mode" in the property bar and set the texture icon before and after the button is pressed. Also bind the tag variable "Play - 1005" to the button control.


In the action list, add the commands that need to be triggered when the button is pressed and released and save them. There are four commands for controlling audio, they are: playSound - play pauseSound - pause resumeSound - restart stopSound - stop


6) Run the simulation. Clicking on the buttons with the mouse will toggle the play/pause state of the music, and you can hear the sound when you put on headphones.


![](../assets_en/声音8.png)