What Does The Angular Say? 🦊

Rate this content
Bookmark

We are very used to generating visual results with code but are still often surprised to hear that we can create music in the same way. Oh, you didn’t know that? You are not alone. Even though the idea of music programming is older than all of us this concept is still pretty unfamiliar among many developers. Not for long! Let's shed some light on music coding in our daily bases web applications using Angular.

This talk has been presented at JSNation Live 2020, check out the latest edition of this JavaScript Conference.

FAQ

The Web Audio API is a sophisticated tool that allows developers to create, modify, and analyze sounds directly in web browsers. It turns browsers into synthesizers by providing functionalities to manipulate audio through programming.

In web applications, audio can be manipulated by creating an audio context to store the state of audio, generating sources like microphones or oscillators, and connecting them to outputs like speakers. Modifications such as filters can be added in between these connections.

ToneJS is a library recommended for handling audio in web applications, particularly noted in MDM documentation. It simplifies the process of creating and manipulating audio, offering predefined elements and utilities for a wide range of audio functions.

To use the ToneJS library in Angular for audio manipulation, install the library using npm, create components for different instruments, and utilize methods like 'playNote' to trigger sounds. ToneJS facilitates easy integration and manipulation of audio elements within Angular frameworks.

Unique instruments created using ToneJS include the 'Katiana' which plays modified cat samples according to pitch, and the 'Doggyana' which uses dog samples. These instruments demonstrate the flexibility of ToneJS in creating custom audio experiences.

Audio can significantly enhance user experience in web development by providing an additional layer of interaction. For instance, integrating responsive audio effects in response to user actions can make applications more engaging and immersive.

Advanced features of ToneJS include various synthesizers like polysynth, parts for playing predefined notes, loops for continuous playback, noise elements with filters, and the ability to adjust general parameters like tempo. These features allow for complex and dynamic audio creations.

Laura Silvanavičiūtė
Laura Silvanavičiūtė
8 min
18 Jun, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

The video demonstrates how to create unique sounds using the Web Audio API and ToneJS in Angular applications. It explains the process of setting up an audio context, connecting sources like microphones or oscillators, and adding filters. The speaker highlights ToneJS as a recommended library for simplifying audio manipulation. Examples include creating instruments like 'Katiana' and 'Doggyana', which play cat and dog samples, respectively. The video also covers using the sampler element to map samples to notes and mentions advanced features such as various synthesizers, parts, noise elements, and audio tracks to enhance user experience.
Available in Español: ¿Qué dice Angular? 🦊

1. Introduction to Angular Sounds and Web Audio API

Short description:

Hello, everybody. Today, I want to show you the sounds of Angular using Web Audio API and ToneJS. We can create our own sounds, modify them, and use browsers as synthesizers. To do this, we need to create an audio context, connect sources like microphones or oscillators, and add filters if needed. ToneJS is a recommended library for this. I will demonstrate how to use ToneJS in an Angular web application to create our own instrument.

Hello, everybody. I'm Laura. I am a front-end developer at Swedbank, and today I want to show you the sounds of Angular. Or in other words, to answer, what does the Angular say? What do I mean here? We are very used to generate visuals for the code but are still often surprised that we can do the same thing for the music as well. We can code music.

And if we are looking into all your possibility in the web, that is nothing new. We have different ways how we can handle music in the web as well. But today I want to focus on the most sophisticated way to do that nowadays, which is Web Audio API. And why it is so great? Web Audio API not only enables us to replay some audio track. Web Audio API enables us to create our own sounds to modify them and analyze as well. So basically it enables us to use browsers as synthesizers.

How does that work? If we have some application for that, we would need to create the audio context to store the state of audio. And everything going to happen there. We would create the sources. That can be your microphone, that can be your oscillators, or it can be audio tracks as well. And then we would need to connect that to the destination, which is usually just speakers. If you would like to add some modifications as filters, that would happen in the middle. And of course there are helpers for that. Because we developers, we love libraries. And there are libraries for that as well. One of them is ToneJS. ToneJS is even recommended if you are reading about the web or the API in MDM documentation. And today I'm going to show you a quick demo of how we can use ToneJS in our web application using Angular. What do I have here so far? I just installed the Tone library symbol with npm install. I as well have the instrument component. So as you understand, we will create our own instrument today. In HTML, I'm just iterating through a bunch of notes. And on click event, I'm calling playNode method. In the component itself, I am taking symf element from the Tone library. And in playNode method, I'm just triggering that exact note with the length of 1 eighth.

2. Exploring Modifications and Different Elements

Short description:

Amazingly, with just a few lines of code, we created an instrument capable of playing any pitch. But we're not stopping there. Let's explore some modifications to make our instrument more unique. We have the Katiana instrument that plays cat samples according to the right pitch. Surprisingly, it was much easier than expected with the help of the ToneJS library. We also have the sampler element, which allows us to map samples to the right note. And don't judge too soon, because I've created something special: the doggyana instrument, which plays dog samples. There are many different elements in this library, including synthesizers, parts, noise, and audio tracks, that can enhance the user experience.

How does that look and sound like? Amazingly, those few lines of code, we created the instrument which is capable to play any pitch you want. But we are not stopping here because so far, we're using just default sounds. And for that, I thought to add some a bit modifications to make our instrument a bit more unique.

We have this is Katiana instrument which plays cat samples but still according the right pitch. And honestly, I was surprised how easy that is to make the ToneJS library, because in my imagination, I thought that I will need to change every sample by myself and then just to map it to the help of Tone library. But that was way easier than this. Let's look into.

We have one more element from Tone library, it is called the sampler. And for sampler initialization, I had to provide the original cat sample, which is here. And then to map it to the right note. So to understand what cat was singing, that was the tough part. But nothing more was needed to provide. All other adjustments were done by the library itself. And you see that in the play note now I'm triggering sampler and synthesizer together.

Now, some of you may think, cat sound instrument, super useful information. But don't judge me too soon. Because for those few of you, I went an extra mile. And I created something else, something special. This is doggyana instrument, which plays dog samples according to the right pitch. But not only this. There are many different elements and I do not want to overhelm you with many different details but just quick overview what you can use in this library. Let's start with different synthesizers, before I was using synth now you see that I have polysynth as well. I can provide different parameters as different oscillators, squares, sines and so on and so on. Then there is the part, part is element which helps you to play predefined notes with predefined instrument. I'm taking for example here chords even from separate constant files and then I have the loop on top of everything and so on. Then different element is noise, noise here I'm not just playing straightly I'm adding the filter, auto filter which makes some waving effect and then back to basics I have some audio tracks I'm playing them randomly and the general parameters is changing tempo, the speed of the microphone, the speed of the mic and speed up a bit so there are many different elements which you can use according to different users actions and usually when we are thinking about front end development our full focus is only on visual parts sometimes we totally forget that we have audio possibility in the dev, but please know that sometimes the right audio can really enrich our visuals and in this way we can create the next level user experience in the dev. And with this, I want to finish up.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

The Wind and the Waves: The formation of Framework Waves from the Epicenter
JSNation 2022JSNation 2022
19 min
The Wind and the Waves: The formation of Framework Waves from the Epicenter
Top Content
Our understanding of innovation is wrong. Innovations are not introduced by a single point of light. The story of who invented the computer is not linear. Many steps forward led to the development of the computer. Angular has shaped and influenced multiple JavaScript waves, and Angular v14 simplifies development with standalone components.
Angular Momentum
JSNation 2023JSNation 2023
22 min
Angular Momentum
Angular has experienced significant growth and is the second most popular framework after React. The latest release of Angular, called Angular Ivy, went through a major refactoring in 2021. Angular's reactivity model has been improved with the introduction of signals, which enable better integration with RxJS and support advanced reactivity patterns. Angular has made optimizations for performance, including improvements in load speed and lazy loading. The Angular team acknowledges the innovations in other frameworks and highlights the impact of introducing TypeScript in enabling the project's success.
Domain Driven Design with Vue Applications
Vue.js London 2023Vue.js London 2023
14 min
Domain Driven Design with Vue Applications
Top Content
Welcome to this talk on domain-driven design in Vue.js application. Today we are going to look into domain-driven design, its benefits and how it works with Vue.js domain-driven design versus the MVVM model. Vue.js thrives in domain-driven design, a design approach that models software to match a domain. DDD emphasizes understanding business logic and creating a domain that reflects the language and concepts. Integrating DDD in Vue.js offers benefits such as effective modeling of complex business domains, structured code reflecting domain logic, and easier onboarding and ownership.
How to Share Code between React Web App and React Native Mobile App in Monorepo
React Summit 2022React Summit 2022
7 min
How to Share Code between React Web App and React Native Mobile App in Monorepo
This presentation focuses on sharing code between React web and React native mobile apps. The speaker demonstrates how to achieve feature parity using a Monorepo with NX. They highlight the importance of sharing non-UI code, such as business logic and state management, through shared libraries. This approach allows the apps to focus on UI code while keeping non-UI code separate. For more details, refer to the speaker's blog post.
Data Loaders - Elevating Data Fetching in Vue
Vue.js Live 2024Vue.js Live 2024
30 min
Data Loaders - Elevating Data Fetching in Vue
Data loaders provide a solution for complex and repetitive data fetching in Vue.js applications. Using data loaders allows for more independent data fetching and integrates with the navigation cycle. The data loader plug-in adds a navigation guard for data fetching and loading. Lazy loading and caching can be implemented using Pina Colada and Glada loaders. These loaders can improve the performance and speed of data fetching in applications.
The Next Wave of Web Frameworks is BYOJS
JSNation 2022JSNation 2022
23 min
The Next Wave of Web Frameworks is BYOJS
The next wave of web frameworks is BYOJS, covering the history and evolution of building web applications. The evolution of web frameworks and build systems includes popular choices like React, Angular, and Vue, as well as advanced build systems like Webpack and Rollup. The rise of performance measurement tools and the adoption of the Jamstack have led to improved web performance. The Jamstack architecture focuses on pre-rendering pages, decoupling APIs and services, and enhancing pages with JavaScript. Astro, a static site generator with SSR support, promotes the islands architecture and partial hydration.

Workshops on related topic

Monitoring 101 for React Developers
React Summit US 2023React Summit US 2023
107 min
Monitoring 101 for React Developers
Top Content
WorkshopFree
Lazar Nikolov
Sarah Guthals
2 authors
If finding errors in your frontend project is like searching for a needle in a code haystack, then Sentry error monitoring can be your metal detector. Learn the basics of error monitoring with Sentry. Whether you are running a React, Angular, Vue, or just “vanilla” JavaScript, see how Sentry can help you find the who, what, when and where behind errors in your frontend project. 
Workshop level: Intermediate
Get started with AG Grid Angular Data Grid
JSNation 2022JSNation 2022
116 min
Get started with AG Grid Angular Data Grid
WorkshopFree
Stephen Cooper
Stephen Cooper
Get started with AG Grid Angular Data Grid with a hands-on tutorial from the core team that will take you through the steps of creating your first grid, including how to configure the grid with simple properties and custom components. AG Grid community edition is completely free to use in commercial applications, so you’ll learn a powerful tool that you can immediately add to your projects. You’ll also discover how to load data into the grid and different ways to add custom rendering to the grid. By the end of the workshop, you will have created and customized an AG Grid Angular Data Grid.
Contents:- getting started and installing AG Grid- configuring sorting, filtering, pagination- loading data into the grid- the grid API- add your own components to the Grid for rendering and editing- capabilities of the free community edition of AG Grid
Micro-Frontends with Module Federation and Angular
JSNation Live 2021JSNation Live 2021
113 min
Micro-Frontends with Module Federation and Angular
Workshop
Manfred Steyer
Manfred Steyer
Ever more companies are choosing Micro-Frontends. However, they are anything but easy to implement. Fortunately, Module Federation introduced with webpack 5 has initiated a crucial change of direction.
In this interactive workshop, you will learn from Manfred Steyer -- Angular GDE and Trusted Collaborator in the Angular team -- how to plan and implement Micro-Frontend architectures with Angular and the brand new webpack Module Federation. We talk about sharing libraries and advanced concepts like dealing with version mismatches, dynamic Module Federation, and integration into monorepos.
After the individual exercises, you will have a case study you can use as a template for your projects. This workshop helps you evaluate the individual options for your projects.
Prerequisites:You should have some experience with Angular.
Web Accessibility in JavaScript Apps
React Summit 2022React Summit 2022
161 min
Web Accessibility in JavaScript Apps
Workshop
Sandrina Pereira
Sandrina Pereira
Often we see JavaScript damaging the accessibility of a website. In this workshop, you’ll learn how to avoid common mistakes and how to use JS in your favor to actually enhance the accessibility of your web apps!
In this workshop we’ll explore multiple real-world examples with accessibility no-nos, and you'll learn how to make them work for people using a mouse or a keyboard. You’ll also learn how screen readers are used, and I'll show you that there's no reason to be afraid of using one!
Join me and let me show you how accessibility doesn't limit your solutions or skills. On the contrary, it will make them more inclusive!
By the end, you will:- Understand WCAG principles and how they're organized- Know common cases where JavaScript is essential to accessibility- Create inclusive links, buttons and toggleble elements- Use live regions for errors and loading states- Integrate accessibility into your team workflow right away- Realize that creating accessible websites isn’t as hard as it sounds ;)
Build a Universal Reactive Data Library with Starbeam
JSNation 2023JSNation 2023
66 min
Build a Universal Reactive Data Library with Starbeam
WorkshopFree
Yehuda Katz
Yehuda Katz
This session will focus on Starbeam's universal building blocks. We'll use Starbeam to build a data library that works in multiple frameworks.We'll write a library that caches and updates data, and supports relationships, sorting and filtering.Rather than fetching data directly, it will work with asynchronously fetched data, including data fetched after initial render. Data fetched and updated through web sockets will also work well.All of these features will be reactive, of course.Imagine you filter your data by its title, and then you update the title of a record to match the filter: any output relying on the filtered data will update to reflect the updated filter.In 90 minutes, you'll build an awesome reactive data library and learn a powerful new tool for building reactive systems. The best part: the library works in any framework, even though you don't think about (or depend on) any framework when you built it.
Table of contents- Storing a Fetched Record in a Cell- Storing multiple records in a reactive Map- Reactive iteration is normal iteration- Reactive filtering is normal filtering- Fetching more records and updating the Map- Reactive sorting is normal sorting (is this getting a bit repetitive?)- Modelling cache invalidation as data- Bonus: reactive relationships