Google Cloud Text to Speech cho website Bát Nhã

Mục tiêu là tạo âm thanh một lần, lưu bản master riêng và chỉ đưa bản đã tối ưu lên website.

Kiến trúc

Bản WAV master:

Google Drive / Bát Nhã Tâm Kinh / Media / Âm thanh gốc

Bản MP3 để website phát:

assets/audio/

Script lời đọc đã biên tập:

audio-scripts/

Xác thực

Không lưu API key hoặc service account key trong repository.

Cài Google Cloud CLI rồi chạy:

gcloud init
gcloud auth application-default login

Sau đó bật Cloud Text to Speech API và billing trong đúng Google Cloud project.

Kiểm tra giọng tiếng Việt

python scripts/google_tts.py voices

Mặc định hiện dùng:

vi-VN-Chirp3-HD-Schedar

Có thể đổi bằng tham số --voice.

Tạo bản master và bản web trong một lần

python scripts/google_tts.py synth \
  --input audio-scripts/14-on-tap-toan-bo-bat-nha.txt \
  --master-output build/audio/14-on-tap-toan-bo-bat-nha-master.wav \
  --output assets/audio/14-on-tap-toan-bo-bat-nha.mp3 \
  --voice vi-VN-Chirp3-HD-Schedar \
  --speaking-rate 0.92

Sau khi nghe và duyệt, upload file WAV master lên Google Drive. Commit file MP3 vào GitHub, rồi thêm vào frontmatter của trang:

audio_src: /assets/audio/14-on-tap-toan-bo-bat-nha.mp3
audio_title: Nghe bản ôn tập
audio_copy: Bản đọc tiếng Việt chậm, rõ, không tự phát.
audio_meta: Có thể vừa nghe vừa theo dõi nội dung bên dưới.

Layout sẽ tự hiện player khi và chỉ khi audio_src được khai báo.

Tối ưu tải trang

Audio dùng preload="none".

Service worker không cache /assets/audio/, request có destination audio hoặc request Range.

Bảo mật

Không commit token, API key, service account JSON hoặc file Application Default Credentials vào GitHub.