Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • p5.js-Environment
  • p5.js-Color
  • p5.js-Shape
  • p5.js-Constants and Structure
  • p5.js-DOM and Rendering
  • p5.js-Transform
  • p5.js-Data
  • p5.js-Events
  • p5.js-Image
  • p5.js-IO
  • p5.js-Math
  • p5.js-Typography
  • p5.js-Lights & Camera
  • JavaScript
  • Web Technology
Open In App
Next Article:
p5.js | SoundFile Object Installation and Methods
Next article icon

p5.js | SoundFile Object Installation and Methods

Last Updated : 22 Jun, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

The SoundFile object is a part of the p5.sound which is a library of JavaScript. This object contains so many functions nearly 30+ functions are there. Each one of them is useful to design a sounded website. By using this object you can easily add audio into your website and play, pause, stop anything you want. To do so you just need to attach the sound library in your index file. To do that we will follow some procedure that is mentioned below one by one.

  • Step 1: First, you have to download the p5.Sound library from this link, after opening this link go for p5.js complete section like below. 
  • Step 2: After downloading the file you have to unzip the folder then you will some files inside the p5.js folder like index.html, sketch.js by opening the index.html file you will see p5.js is already linked to it you can change that for faster performance by replacing that script with the below script. 

<script src="../p5.min.js"></script>

The Sample HTML page may look like this: 

HTML
<!DOCTYPE html> <html>     <head>         <script src=”../p5.min.js”></script>         <script src="sketch.js"></script>     </head>          <body>     </body> </html> 
  • Step 3:In this step, we will set up the code editor for p5.js. The best code editor, in my opinion, is Brackets, Atom. But you can use others also like Notepad++, Sublime, etc.
  • Step 4: Now open your editor and trace down to your p5.js folder location and open the sketch.js file. In this file we will perform the task, here we will write our script to test this library and use them on our website.
  • Step 5: In this step, you will get to know how to use it. 
JavaScript
function setup() {  }  function draw() {   ellipse(50, 50, 80, 80); } 

You will get something like this: 
 


List of all the functions p5.SoundFile: 

FunctionDescription
loadSound()This function is used to load the sound.
isLoaded()This function is used to check the sound is loaded or not.
play()This function is use to play the loaded sound.
playMode()This function is used to play the sound in two playing mode restart and sustain.
pause()This function is used to pause the played sound.
loop()This function is used to create the loop of that sound.
islooping()This function is used to check the loop function called or not.
setLoop()This function is used to create loop define number of times.
isPlaying()This function is used to check audio is playing or not.
isPaused()This function is used to check audio is paused or not.
stop()This function is used to stop the played audio.
setVolume()This function is used to set the volume of the audio range is 0 to 1.
pan()This function is used to set the left right pan of the audio range is -1(left) to 1(right).
getPan()This function is used to check the pan side.
rate()This function is used to set the playing speed of the audio.
duration()This function is used to get the duration of the audio.
currentTime()This function is used to get the current time of the playing audio.
jump()This function is used to jump at some specific point of the audio.
channels()This function is used to get the channels Mono means 1 Stereo means 2.
sampleRate()This function is used to get the samplerate per second of the audio.
frames()This function is used to get the frames of the audio, where frames= samplesrate * duration.
getPeaks()This function is used to get the array of amplitude peaksof the audio.
reverseBuffer()This function is used to play the audio in reverse way.
onended()This function is used to call event after ending the audio.
connect()This function is used to connects the output of a p5sound object to input of another p5.sound object.
disconnect()This function is used to disconnects the output of this p5sound object.
setPath()This function is used to set the path for the audio.
setBuffer()This function is used to set the buffer for the audio.
processPeaks()This function is used to get the beats of the audio.
addCue()This function is used to add events after specified time.
removeCue()This function is used to remove specific event that was schedule by the addCue function.
clearCues()This function is to clear all the event that was scheduled by the addCue function.
save()This function is used to save the audio in locally.
getBlob()This function is used to upload the audio in the server.


 


Next Article
p5.js | SoundFile Object Installation and Methods

S

skyridetim
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • JavaScript-p5.js

Similar Reads

    How to Install NPM FS in Node JS ?
    The file system module allows you to work with the file system on your computer NodeJS includes the fs module, to communicate with file systems. It provides functionality for interacting with the file system, such as reading from and writing to files, creating and removing directories, etc. The File
    4 min read
    p5.js soundFormats() Function
    The soundFormats() function is used to store the array of sound file format extension formats. Like .mp3, .ogg, .wav, etc. You have to upload all the format in your server the client browser-supported format will be chosen from this array and will play it. Syntax:soundFormats( formats )Note: All the
    1 min read
    p5.MediaElement showControls() Method
    The showControls() method of p5.MediaElement in p5.js is used to show the default media controls for the media element. The control features and design of the controls are determined by the web browser.Syntax:showControls()Parameters: This method does not accept any parameters.The example below illu
    1 min read
    p5.js MediaElement duration() Method
    The duration() method of p5.MediaElement in p5.js library is used to return the duration of the media element on which it is called. This duration that is returned is displayed in seconds. Syntax: duration() Parameters: This function does not accept any parameters. Return Value: This method returns
    1 min read
    How to play a notification sound on websites?
    There are various ways to play a notification sound on a website. IN this article we will play the notification sound in three different ways: Using Onclick Event in JavaScript Using Audio class in JavaScript Using pure Jquery: Below all the procedures are explained in details with the exxampl code:
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences