🎵 SunoMaker - Automated Suno AI Music Generation
Designed for Linux servers without a graphical interface (Headless). Uses Xvfb Virtual Display to run Chrome in GUI mode without a monitor, bypassing Google's anti-automation systems.
Two core functions: Account Login (via Google OAuth) and Song Creation (custom lyrics + style + download).
0. Prerequisite Check
Before any operation, the environment must be checked:
CODEBLOCK0
Return values:
- -
0 = OK, logged in → songs can be created directly - INLINECODE1 = Dependencies missing → installation required
- INLINECODE2 = Not logged in → start the login process
1. Install Dependencies (first time only)
1.1 System Dependencies
CODEBLOCK1
1.2 Python Dependencies
CODEBLOCK2
2. Login Process
⚠️ Important: Never hardcode credentials in the code! Always ask the user.
Two login methods are available:
- - Method A: Cookie Import (🌟 Recommended! Perfectly bypasses Google security checks)
- Method B: Direct Email/Password Login (can trigger Google security prompts)
2.1 Method A: Cookie Import (Recommended)
The most stable login method for cloud servers. Completely bypasses Google's security checks.
Steps:
If login is required, explain to the user:
🍪 Recommended Cookie Import Method (bypasses Google security checks):
Step 1: On your local computer (with a browser), run:
> pip install playwright && playwright install
> python3 export_cookies.py
>
A browser window will open. Log in to Suno manually. After a successful login, cookies will be exported automatically.
Step 2: Upload the cookie file to the server:
> scp <exported-cookie-file> user@server:/root/suno_cookie/suno_cookies.json
>
Step 3: After uploading, perform the import.
After uploading, run the import (default path: /root/suno_cookie/suno_cookies.json):
CODEBLOCK5
2.2 Method B: Email/Password Login
⚠️ Caution: On cloud servers, this can trigger Google security prompts. Prefer Method A.
If login is required, always ask the user:
Suno.com login required (via Google account). Please provide:
- 1. Gmail address
- Gmail password
⚠️ Credentials are only used for this login, not stored or shared with third parties.
After user input:
CODEBLOCK6
Headless Linux Mode Explanation:
- - The script automatically detects a GUI-free environment (no
$DISPLAY variable) - It automatically starts an Xvfb Virtual Display, simulating a display in memory
- Chrome runs in GUI mode (
headless=False), but nothing is displayed on the screen - This bypasses Google's headless browser detection
2.3 Check Login Status
CODEBLOCK7
Exit codes: 0 = Logged in, 2 = Not logged in
2.4 Force Re-login
CODEBLOCK8
3. Create a Song
3.1 Prerequisites
- 1. Logged in (
suno_login.py --check-only returns 0) - Gemini API Key required (for automatic hCaptcha solving)
3.2 Get a Gemini API Key
If the user does not have a Gemini API Key:
When creating a song, Suno shows captchas. A Gemini API Key is required for automatic solving.
- 1. Visit https://aistudio.google.com/app/apikey
- Click "Create API key"
- Copy the generated key
Save it in an environment file:
CODEBLOCK9
Or as an environment variable:
CODEBLOCK10
3.3 hCaptcha Compatibility Patch
Run this once before the first use (Suno uses its own hCaptcha domain, a patch is required):
CODEBLOCK11
3.4 Song Creation Command
CODEBLOCK12
Read lyrics from a file:
CODEBLOCK13
Headless Mode Explanation:
- -
suno_create_song.py automatically detects a GUI-free environment - It automatically starts an Xvfb Virtual Display, running Chrome in GUI mode in the virtual display
- After the script finishes, the Virtual Display is automatically closed, no manual action needed
3.5 Parameter Explanation
| Parameter | Description | Required | Default Value |
|---|
| INLINECODE10 | Song lyrics (alternative to --lyrics-file) | ✅ | - |
| INLINECODE12 |
Path to the lyrics file (alternative to
--lyrics) | ✅ | - |
|
--style | Music style tags (English, comma-separated) | ❌ |
rock, electric guitar, energetic, male vocals |
|
--title | Song title | ❌ |
My Song |
|
--output-dir | MP3 download directory | ❌ |
{baseDir}/output_mp3 |
|
--gemini-key | Gemini API Key (alternatively: environment variable or
~/.suno/.env) | ❌ | Auto-Read |
3.6 Music Style Tags Reference
Common style tags (English, combinable):
- - Genres: rock, pop, jazz, blues, electronic, hip-hop, R&B, classical, folk, metal, country, reggae, latin, indie
- Instruments: electric guitar, acoustic guitar, piano, synthesizer, drums, bass, violin, saxophone, trumpet
- Mood: energetic, emotional, melancholic, upbeat, dark, dreamy, aggressive, peaceful, romantic
- Vocals: male vocals, female vocals, choir, rap, whisper, powerful vocals, falsetto
- Language: german, english, french, spanish, chinese, japanese
- Other: fast tempo, slow tempo, instrumental, lo-fi, cinematic, epic
Examples:
- - Rock: INLINECODE22
- Ballad: INLINECODE23
- Electronic: INLINECODE24
- Hip-Hop: INLINECODE25
4. Complete Example
Example: Create a Rock Song on a Linux Server
CODEBLOCK14
5. Differences from the Original Version
| Feature | suno (Original) | suno-headless (This Version) |
|---|
| Target Environment | macOS / Linux with GUI | Linux Server without GUI |
| Display Mode |
Real Chrome window |
Xvfb Virtual Display (RAM simulation) |
| Additional Dependencies | None |
xvfb +
PyVirtualDisplay |
| Login Xvfb | ✅ Supported | ✅ Supported |
| Song Creation Xvfb | ❌ Not supported | ✅
Supported |
| Environment Check | Basic |
Incl. Xvfb/Chrome/Font Check |
6. Technical Details
Xvfb Virtual Display Solution
CODEBLOCK15
- - Why not headless=True? Google OAuth detects headless browsers and blocks logins
- Xvfb solution: Creates a virtual X11 display in RAM, Chrome "thinks" there's a real GUI, so Google can't detect the automation
- Auto-detection: The script checks the
$DISPLAY environment variable and starts Xvfb automatically if no GUI is present - Resources: Xvfb uses minimal RAM and is automatically released after the script finishes
Login Solution
- - Playwright + Real Chrome browser (
channel='chrome') - INLINECODE30 maintains browser state (cookies, localStorage)
- INLINECODE31 + Xvfb Virtual Display bypasses Google's anti-automation
- After the first login, the session is maintained through the persistent context
Song Creation Solution
- - Browser automation controls the suno.com/create page
- hcaptcha-challenger + Gemini API solves hCaptcha automatically
- New clip ID is obtained by intercepting browser network responses
- Suno's internal API (
studio-api.prod.suno.com) polls the song generation status - Automatic MP3 download upon completion
File Structure
CODEBLOCK16
7. Important Notes
- 1. Never hardcode credentials — Always ask the user (prefer cookie import)
- Xvfb must be installed —
sudo apt install -y xvfb, otherwise it won't run in a headless environment - Real Chrome is required — Playwright's own Chromium can be detected by Google
- Suno Free accounts have a daily point limit, approx. 100 points per song
- Song generation typically takes 1-3 minutes
- Each creation generates 2 different song versions
- If Google login is rejected: wait 10-30 minutes, then try again
- Gemini API Free limit: 15 Requests/Minute, 1500/Day
- hCaptcha may take several attempts, success rate depends on Gemini's image recognition
8. Troubleshooting
CODEBLOCK17
🎵 SunoMaker - 自动化Suno AI音乐生成
专为无图形界面的Linux服务器(无头模式)设计。使用Xvfb虚拟显示器在无显示器的情况下以GUI模式运行Chrome,绕过谷歌的反自动化系统。
两个核心功能:账户登录(通过Google OAuth)和歌曲创作(自定义歌词+风格+下载)。
0. 前置检查
在任何操作之前,必须检查环境:
bash
bash {baseDir}/suno-headless/check_env.sh
返回值:
- - 0 = 正常,已登录 → 可直接创建歌曲
- 1 = 缺少依赖 → 需要安装
- 2 = 未登录 → 启动登录流程
1. 安装依赖(仅首次)
1.1 系统依赖
bash
Xvfb虚拟显示器(无头环境的核心依赖)
sudo apt update && sudo apt install -y xvfb
Google Chrome浏览器
wget -q -O - https://dl.google.com/linux/linux
signingkey.pub | sudo apt-key add -
echo deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main | sudo tee /etc/apt/sources.list.d/google-chrome.list
sudo apt update && sudo apt install -y google-chrome-stable
多语言字体
sudo apt install -y fonts-noto-cjk
1.2 Python依赖
bash
cd {baseDir}/suno-headless
pip3 install -r requirements.txt
playwright install
2. 登录流程
⚠️ 重要:切勿在代码中硬编码凭据!始终询问用户。
提供两种登录方式:
- - 方式A:Cookie导入(🌟 推荐!完美绕过谷歌安全检测)
- 方式B:直接邮箱/密码登录(可能触发谷歌安全提示)
2.1 方式A:Cookie导入(推荐)
云服务器最稳定的登录方式。完全绕过谷歌的安全检测。
步骤:
如果需要登录,向用户说明:
🍪 推荐使用Cookie导入方式(绕过谷歌安全检测):
步骤1:在本地电脑(有浏览器)上运行:
bash
pip install playwright && playwright install
python3 export_cookies.py
将打开浏览器窗口。手动登录Suno。登录成功后,Cookie将自动导出。
步骤2:将Cookie文件上传到服务器:
bash
scp <导出的cookie文件> user@server:/root/sunocookie/sunocookies.json
步骤3:上传后,执行导入。
上传后,运行导入(默认路径:/root/sunocookie/sunocookies.json):
bash
cd {baseDir}/suno-headless
python3 suno_login.py --import-cookies
2.2 方式B:邮箱/密码登录
⚠️ 注意:在云服务器上,这可能会触发谷歌安全提示。优先使用方式A。
如果需要登录,始终询问用户:
需要登录Suno.com(通过Google账户)。请提供:
- 1. Gmail邮箱地址
- Gmail密码
⚠️ 凭据仅用于本次登录,不会存储或与第三方共享。
用户输入后:
bash
cd {baseDir}/suno-headless
python3 suno_login.py --email <用户邮箱> --password <用户密码>
无头Linux模式说明:
- - 脚本自动检测无GUI环境(无$DISPLAY变量)
- 自动启动Xvfb虚拟显示器,在内存中模拟显示器
- Chrome以GUI模式运行(headless=False),但屏幕上不显示任何内容
- 这绕过了谷歌的无头浏览器检测
2.3 检查登录状态
bash
cd {baseDir}/suno-headless
python3 suno_login.py --check-only
退出码:0 = 已登录,2 = 未登录
2.4 强制重新登录
bash
方式A:重新导入Cookie
cd {baseDir}/suno-headless
python3 suno_login.py --import-cookies <新cookie文件>
方式B:重新输入邮箱/密码
cd {baseDir}/suno-headless
python3 suno_login.py --email <邮箱> --password <密码> --force-login
3. 创建歌曲
3.1 前置条件
- 1. 已登录(suno_login.py --check-only 返回0)
- 需要Gemini API密钥(用于自动解决hCaptcha验证码)
3.2 获取Gemini API密钥
如果用户没有Gemini API密钥:
创建歌曲时,Suno会显示验证码。需要Gemini API密钥来自动解决。
- 1. 访问 https://aistudio.google.com/app/apikey
- 点击创建API密钥
- 复制生成的密钥
将其保存在环境文件中:
bash
mkdir -p ~/.suno
echo GEMINIAPIKEY=<用户密钥> > ~/.suno/.env
或者作为环境变量:
bash
export GEMINIAPIKEY=<用户密钥>
3.3 hCaptcha兼容性补丁
首次使用前运行一次(Suno使用自己的hCaptcha域名,需要补丁):
bash
cd {baseDir}/suno-headless
python3 patch_hcaptcha.py
3.4 歌曲创建命令
bash
cd {baseDir}/suno-headless
python3 sunocreatesong.py \
--lyrics <歌词内容> \
--style <音乐风格标签> \
--title <歌曲标题> \
--output-dir <下载目录>
从文件读取歌词:
bash
cd {baseDir}/suno-headless
python3 sunocreatesong.py \
--lyrics-file <歌词文件路径> \
--style <音乐风格标签> \
--title <歌曲标题>
无头模式说明:
- - sunocreatesong.py 自动检测无GUI环境
- 自动启动Xvfb虚拟显示器,在虚拟显示器中以GUI模式运行Chrome
- 脚本完成后,虚拟显示器自动关闭,无需手动操作
3.5 参数说明
| 参数 | 描述 | 必需 | 默认值 |
|---|
| --lyrics | 歌词(与--lyrics-file二选一) | ✅ | - |
| --lyrics-file |
歌词文件路径(与--lyrics二选一) | ✅ | - |
| --style | 音乐风格标签(英文,逗号分隔) | ❌ | rock, electric guitar, energetic, male vocals |
| --title | 歌曲标题 | ❌ | My Song |
| --output-dir | MP3下载目录 | ❌ | {baseDir}/output_mp3 |
| --gemini-key | Gemini API密钥(也可用环境变量或~/.suno/.env) | ❌ | 自动读取 |
3.6 音乐风格标签参考
常用风格标签(英文,可组合):
- - 流派:rock, pop, jazz, blues, electronic, hip-hop, R&B, classical, folk, metal, country, reggae, latin, indie
- 乐器:electric guitar, acoustic guitar, piano, synthesizer, drums, bass, violin, saxophone, trumpet
- 情绪:energetic, emotional, melancholic, upbeat, dark, dreamy, aggressive, peaceful, romantic
- 人声:male vocals, female vocals, choir, rap, whisper, powerful vocals, falsetto
- 语言:german, english, french, spanish, chinese, japanese
- 其他:fast tempo, slow tempo, instrumental, lo-fi, cinematic, epic
示例:
- - 摇滚:rock, electric guitar, energetic, male vocals, english
- 抒情:pop, piano, emotional, female vocals, slow tempo, english
- 电子:electronic, synthesizer, upbeat, fast tempo, dance
- 嘻哈:hip-hop, rap, bass, drums, energetic, english
4. 完整示例
示例:在Linux服务器上创建摇滚歌曲
bash
1. 检查环境(自动检测Xvfb、Chrome等)
bash {baseDir}/suno-headless/check_env.sh
2. 如果未登录,使用Cookie导入方式(推荐)
步骤1:在本地电脑上运行export_cookies.py
步骤2:scp user@server:/root/sunocookie/sunocookies.json
步骤3:在服务器上导入(默认