Unofficial API for Google's MusicLM on the AI Test Kitchen
- Google Chrome
- Python >= 3.6
- Selenium
- undetected_chromedriver
- python-dotenv
- requests
- Install Python 3 from the official website: https://www.python.org/downloads/
- Run the following command in your terminal to install the required libraries:
pip install selenium undetected-chromedriver python-dotenv requests
- Before running the script, make sure you have a Google account that has access to the AI Test Kitchen. Join the waitlist here.
- Clone the repository and navigate to the directory containing the script.
- Rename the file
example.env
to.env
- Store Google sign-in details in the
.env
file (necessary to obtain OAuth2.0 token that is used to generate music) - Create a new Python file and import the Music class from the
MusicLM.py
file.
from MusicLM import Music
- Create an instance of the
Music
class.
music = Music()
- Call the
get_tracks
method on the instance and provide a string input and an integergenerationCount
argument (8 max).
input = "Ambient, soft sounding music I can study to"
tracks = music.get_tracks(input, 2)
- Call the
base64toMP3
method on the instance and provide the returned tracks from theget_tracks
method and a filename.
music.base64toMP3(tracks, input)
- The generated tracks will be saved to a new directory with the same name as the input string.
The Music
class handles authentication using a headless Chrome browser that obtains the OAuth 2.0 authentication token. The get_token
method logs the user in to the AI Test Kitchen website and retrieves the OAuth 2.0 token from the browser's cookies. The token is saved to a .env
file. The token expires every hour and is refreshed automatically using the token_refresh
method.
The Music
class uses the requests
library to make a POST request to an API with the input string and the number of tracks to generate. The API returns a JSON object containing the base64-encoded audio data for each track. The base64-encoded audio data is decoded with the base64toMP3
method and each track is saved as an MP3 file.
Normally if you input popular media references, it returns an error inferring that it can't generate it (presumably due to copyright issues)
But simply enclosing the references <>
bypasses it for some reason and works as expected, like here the output music is an unmistakable combination of Attack on Titan's OST's time signature & instruments and the dramatic undertone of Dark Souls OST.
Video.mp4
This bypass was discovered and shared by ArpanTripathi on Twitter
https://twitter.com/ArpanTripathi20/status/1661292475892285441
This tool is for educational purposes only and should not be used for any commercial or illegal activities. The author is not responsible for any misuse of this tool.
OsError: [WinError 6] The handle is invalid
- refer to this issue: ultrafunkamsterdam/undetected-chromedriver#1256