VOOZH about

URL: https://www.analyticsvidhya.com/blog/2020/11/generate-carnatic-music-with-google-magenta/

⇱ Generate Your Own Carnatic Music With Google Magenta


India's Most Futuristic AI Conference Is Back – Bigger, Sharper, Bolder

  • d
  • :
  • h
  • :
  • m
  • :
  • s

Reading list

Generate Carnatic Music with Google Magenta

Prasad Last Updated : 23 Nov, 2020
4 min read

This article was published as a part of the Data Science Blogathon.

Music is the rhythm of the life

Music is a universal language. It has the ability to effortlessly transcend the opaque body, subtle mind, and invisible soul. At the end of a long hard-working day, listening to your favorite music composition can give a much-needed solace and fresh energy to look forward to dealing with life with a smile.

In this article, I focused on the following topics:

  1. Play and visualize Carnatic Music Ragas using Google Magenta library
  2. Generate Carnatic Music Raga notes using machine learning techniques
  3. Generate random Carnatic Music Raga notes with simple python scripts

Introduction

Having learned the basics of Carnatic Music in my childhood, I always had the fascination to automate generating this ancient form of South Indian classical music. Hindustani Music is popular in North India. Indian film music is more popular nowadays, which often takes inspiration from both these classical forms of music.

In the pursuit of a good tool to generate music, I came across the Google Magenta project. It has a simple yet powerful way to generate Note sequence music. My attempt to generate Carnatic music with this tool is presented here.

Basics of Carnatic Music vis–à–vis Western Music

Western music has scales and notes generated by the keys with Major and Minor scales, whereas Indian Classical music has Ragam or Raga which is more than a set of notes or swaras.

Western music generated with notes is discrete by design. Raga is continuous and captures human emotion along with mood, expression, and energy.

Despite many differences, fortunately, both are based on 12 keynotes or swaras which can help in generating Indian classical music from a broader perspective, ignoring the microtonal perfections.

Let’s see how Indian Classical music (Carnatic Music) notes map to Electronic Piano notes to understand the similarities and possibilities for Carnatic Music generation.

Unlike the western music system where swaras/notes frequencies are fixed; in the Indian classical music system variations in few notes are allowed. This scheme envisages β€˜Sa’ and β€˜Pa’ as fixed notes, with β€˜Ma’ having 2 variants and the remaining swaras having 3 variants each. Swaras/Notes and their variations are given in above table.

In total, Carnatic Music considers 16 Swaras/Notes for classifying and accommodating a rich variety of Ragas.

”Ma” is the median among 7 major swaras. Since β€˜Ma’ has 2 variants, it divides the Root Ragams also called β€œMelakarta” Ragams or Parent Ragams into two equal parts. This picture below depicts the division of these 72 major Ragams which have all 7 major swaras. Thousands of Child Ragas are derived by adding, omitting, or transposing the notes from these 72 main Ragas.

1.Carnatic Music with Magenta

Enough of theory, now let’s jump into Carnatic Music generation using Google Magenta.

Click this link to run the below examples yourself. This is the easiest way to get started with Magenta. Here, you can generate music, download it as MIDI and also see the graphical music patterns with Bokeh library.

Everything in Magenta is centered around NoteSequences. This is a fantastic abstract representation of a series of notes, each with different pitches or srutis, instruments and strike velocities, much like MIDI.

The beginners of Carnatic Music are first taught with Mayamalavagowla Ragam, the 15th Melakarta (see the chart above). It has the following notes/swaras.

sa, ri1, ga2, ma1, pa, da1, ni2

The ascending order (Aarohana) and descending order (Avarohana) have all the same 7 swaras, which is a common property for all Melakarta Ragams. The following python script plays this ragam notes. Run this code in Step 1 of the Hello Magenta Colab window given above.

Visualizing the Ragas

The above code generates  the graph and note sequence as MIDI file for 3 ragas.

You can observe the symmetry of notes in the graph, which may be the reason, new students are started with this  Mayamalavagowla Ragam.

Punching the main keynotes on piano will generate Sankarabharam Ragam, which appears to be a platykurtic gaussian normal distribution.

Music is all about melodious patterns

A new student is taught to sing/play some notes/swaras patterns. Here is a code snippet for one such beautiful pattern called sarali swaram.

Any ragam with the same ascending order and descending order notes can be played with the above pattern

Generating variable-length note sequences

Many times, notes/swaras need to played at variable lengths.  NoteSequence has provided this feature with start_time and end_time parameters. This this code generates notes for one such basic composition called Pillari Geetam.

2. Generate Raga notes using Melody_RNN

Till now, we just used NoteSequence to generate Carnatic Raga Notes. Now, let’s try to generate music with the Recurrent Neural Network model developed by the Google Magenta team.

A MelodyRNN is an LSTM-based language model for musical notes β€” it is best at continuing a NoteSequence that you give it. Try running this this code in Step-2 of the Hello Magenta Colab file to see the result of generating Carnatic Raga Notes using Melody_RNN.

I saw that the output sequence generated by Melody_RNN does go beyond the given Raga Notes. A single note change can result in deviation from Raga’s pattern. This is not as desirable as per the rigid properties of Raga.

3. Generate random  Raga notes with simple Python Scripts

When complex things are not working, try simple options

This is a simple this code to generate random Raga Notes with variable lengths.  This script generates only the notes present in the Raga.  This is a very simple one and serves the basic purpose of random notes generation.

Conclusion

In this article, I attempted to explore the possibilities of generating Carnatic Music Raga notes with Magenta NoteSequence. Automatic Note sequence can be generated with Melody_RNN, but it produced notes beyond Raga pattern notes. So, I provided a simple random notes generator, that may serve basic needs while confining to Raga note sequence limits.

Login to continue reading and enjoy expert-curated content.

Free Courses

Ensemble Learning and Ensemble Learning Techniques

Learn ensemble learning, its techniques, and how it works in this course!

Dimensionality Reduction for Machine Learning

Master key dimensionality reduction techniques for ML success!

Responses From Readers

Raghunandan

Congratulations on publishing this interesting write-up about Karnataka Classical music and the app 'Magenta'.

Pradeep Kumar

Beutiful ...We appreciate your dedicated hardwork to bring all the music lovers together...

Very interesting! Going to try it out!

Flagship Programs

GenAI Pinnacle Program| GenAI Pinnacle Plus Program| AI/ML BlackBelt Program| Agentic AI Pioneer Program

Free Courses

Generative AI| DeepSeek| OpenAI Agent SDK| LLM Applications using Prompt Engineering| DeepSeek from Scratch| Stability.AI| SSM & MAMBA| RAG Systems using LlamaIndex| Building LLMs for Code| Python| Microsoft Excel| Machine Learning| Deep Learning| Mastering Multimodal RAG| Introduction to Transformer Model| Bagging & Boosting| Loan Prediction| Time Series Forecasting| Tableau| Business Analytics| Vibe Coding in Windsurf| Model Deployment using FastAPI| Building Data Analyst AI Agent| Getting started with OpenAI o3-mini| Introduction to Transformers and Attention Mechanisms

Popular Categories

AI Agents| Generative AI| Prompt Engineering| Generative AI Application| News| Technical Guides| AI Tools| Interview Preparation| Research Papers| Success Stories| Quiz| Use Cases| Listicles

Generative AI Tools and Techniques

GANs| VAEs| Transformers| StyleGAN| Pix2Pix| Autoencoders| GPT| BERT| Word2Vec| LSTM| Attention Mechanisms| Diffusion Models| LLMs| SLMs| Encoder Decoder Models| Prompt Engineering| LangChain| LlamaIndex| RAG| Fine-tuning| LangChain AI Agent| Multimodal Models| RNNs| DCGAN| ProGAN| Text-to-Image Models| DDPM| Document Question Answering| Imagen| T5 (Text-to-Text Transfer Transformer)| Seq2seq Models| WaveNet| Attention Is All You Need (Transformer Architecture) | WindSurf| Cursor

Popular GenAI Models

Llama 4| Llama 3.1| GPT 4.5| GPT 4.1| GPT 4o| o3-mini| Sora| DeepSeek R1| DeepSeek V3| Janus Pro| Veo 2| Gemini 2.5 Pro| Gemini 2.0| Gemma 3| Claude Sonnet 3.7| Claude 3.5 Sonnet| Phi 4| Phi 3.5| Mistral Small 3.1| Mistral NeMo| Mistral-7b| Bedrock| Vertex AI| Qwen QwQ 32B| Qwen 2| Qwen 2.5 VL| Qwen Chat| Grok 3

AI Development Frameworks

n8n| LangChain| Agent SDK| A2A by Google| SmolAgents| LangGraph| CrewAI| Agno| LangFlow| AutoGen| LlamaIndex| Swarm| AutoGPT

Data Science Tools and Techniques

Python| R| SQL| Jupyter Notebooks| TensorFlow| Scikit-learn| PyTorch| Tableau| Apache Spark| Matplotlib| Seaborn| Pandas| Hadoop| Docker| Git| Keras| Apache Kafka| AWS| NLP| Random Forest| Computer Vision| Data Visualization| Data Exploration| Big Data| Common Machine Learning Algorithms| Machine Learning| Google Data Science Agent
πŸ‘ Av Logo White

Continue your learning for FREE

Forgot your password?
πŸ‘ Av Logo White

Enter OTP sent to

Edit

Wrong OTP.

Enter the OTP

Resend OTP

Resend OTP in 45s

πŸ‘ Popup Banner
πŸ‘ AI Popup Banner