μ΄ μ±λ¦°μ§ λ©μ λͺ©νλ Google Cloudμ Speech-to-Text, Text-to-Speech, Translation APIλ₯Ό μ¬μ©νλ κ²μ λλ€. λ€μ κ°μ΄λλ₯Ό λ°λΌ μ°¨κ·Όμ°¨κ·Ό μ§ννμλ©΄ λ©λλ€.
π οΈ νμ€ν¬ 1. API ν€ μμ±
μ΄ λ©μ λͺ¨λ API νΈμΆμλ μΈμ¦μ΄ νμν©λλ€. λ¨Όμ API ν€λ₯Ό λ§λ€μ΄μΌ ν©λλ€.
Google Cloud Consoleμ μ μν©λλ€.
μΌμͺ½ νμ λ©λ΄μμ API λ° μλΉμ€(APIs & Services) > **μ¬μ©μ μΈμ¦ μ 보(Credentials)**λ‘ μ΄λν©λλ€.
μλ¨μ μλ **+ μ¬μ©μ μΈμ¦ μ 보 λ§λ€κΈ°(+ CREATE CREDENTIALS)**λ₯Ό ν΄λ¦νκ³ , λλ‘λ€μ΄ λ©λ΄μμ **API ν€(API key)**λ₯Ό μ νν©λλ€.
μλ‘μ΄ API ν€κ° μμ±λλ©΄, ν€ κ°μ 볡μ¬νμ¬ λ©λͺ¨ν΄ λ‘λλ€. μ΄ ν€λ λμ€μ μ¬μ©ν μ μμ΅λλ€.
API μ ν(API restrictions) νμμ νμν API(μ: Cloud Translation API)λ₯Ό μ ννμ¬ ν€μ λν μ κ·Όμ μ ννλ κ²μ΄ 보μμ μ’μ§λ§, μ΄ λ©μμλ νμλ μλλλ€.
π£οΈ νμ€ν¬ 2. Text-to-Speech APIλ‘ μμ± ν©μ±
μ΄ νμ€ν¬μμλ ν μ€νΈ νμΌμ μμ± νμΌ(.mp3)λ‘ λ³νν©λλ€.
SSHλ₯Ό ν΅ν΄ lab-vm μΈμ€ν΄μ€μ μ μν©λλ€.
κ°μ νκ²½μ νμ±νν©λλ€:
| source venv/bin/activate |
| nano synthesize-text.json |
λͺ λ Ήμ΄λ₯Ό μ¬μ©νμ¬ νμΌμ μμ±νκ³ , λ€μ JSON λ΄μ©μ λΆμ¬λ£κΈ° ν©λλ€.
JSON
| { “input”:{ “text”:”Cloud Text-to-Speech API allows developers to include natural-sounding, synthetic human speech as playable audio in their applications. The Text-to-Speech API converts text or Speech Synthesis Markup Language (SSML) input into audio data like MP3 or LINEAR16 (the encoding used in WAV files).” }, “voice”:{ “languageCode”:”en-gb”, “name”:”en-GB-Standard-A”, “ssmlGender”:”FEMALE” }, “audioConfig”:{ “audioEncoding”:”MP3″ } } |
Text-to-Speech APIλ₯Ό νΈμΆνμ¬ synthesize-text.txt νμΌμ κ²°κ³Όλ₯Ό μ μ₯ν©λλ€.
Bash
| gcloud ml tts synthesize-text –request-file=synthesize-text.json > synthesize-text.txt |
nano tts_decode.py λͺ λ Ήμ΄λ‘ νμ΄μ¬ μ€ν¬λ¦½νΈλ₯Ό λ§λ€κ³ , μ 곡λ μ½λλ₯Ό λΆμ¬λ£κΈ° ν©λλ€.
λ€μ λͺ λ Ήμ΄λ₯Ό μ€ννμ¬ .txt νμΌμ .mp3 νμΌλ‘ λμ½λ©ν©λλ€.
Bash
| python tts_decode.py –input “synthesize-text.txt” –output “synthesize-text-audio.mp3” |
synthesize-text-audio.mp3 νμΌμ΄ μμ±λλ©΄, VMμ SSH μΈμ μμ λ€μ΄λ‘λνμ¬ μμ± νμΌμ λ€μ΄λ΄ λλ€.
ποΈ νμ€ν¬ 3. Speech-to-Text APIλ‘ μμ± ν μ€νΈ λ³ν
μ΄ νμ€ν¬μμλ .flac μ€λμ€ νμΌμ ν μ€νΈλ‘ λ³νν©λλ€. μ΄μ μ λ°μνλ μ€λ₯λ€μ λ°νμΌλ‘ μ νν λͺ λ Ήμ΄λ₯Ό μλ΄ν΄ λλ¦¬κ² μ΅λλ€.
speech_request_fr.json νμΌμ μμ±νλ κ²μ μ΄ νμ€ν¬λ₯Ό ν΄κ²°νλ λ° νμνμ§ μμ΅λλ€. gcloud λͺ λ Ήμ΄λ νμΌμ μ§μ μ¬μ©νμ§ μκ³ νλκ·Έ(flag) ννλ‘ μΈμλ₯Ό λ°μ΅λλ€.
gs://cloud-samples-data/speech/corbeau_renard.flac νμΌμ νλμ€μ΄λ‘ λμ΄ μμΌλ©°, ν€λ μ 보μ λ°λ₯΄λ©΄ **λ¨μΌ μ±λ(mono)**μ λλ€. μ΄ μ 보λ API νΈμΆ μ λ§€μ° μ€μν©λλ€.
λ€μ λͺ λ Ήμ΄λ₯Ό μ¬μ©νμ¬ Speech-to-Text APIλ₯Ό νΈμΆνκ³ κ²°κ³Όλ₯Ό speech_response.json νμΌμ μ μ₯ν©λλ€. μ΄ λͺ λ Ήμ΄λ gcloudκ° μꡬνλ μ νν νμμ λλ€.
Bash
| gcloud ml speech recognize-long-running gs://cloud-samples-data/speech/corbeau_renard.flac –language-code=fr-FR –encoding=FLAC –sample-rate=44100 > speech_response.json |
recognize-long-running: 60μ΄ μ΄μμ κΈ΄ μ€λμ€ νμΌμ μ¬μ©λλ λͺ λ Ήμ΄μ λλ€.
–language-code: fr-FRλ‘ μ§μ νμ¬ νλμ€μ΄λ₯Ό μΈμνλλ‘ ν©λλ€.
–encodingκ³Ό –sample-rate: μ€λμ€ νμΌμ μΈμ½λ© λ° μνλ§ μλλ₯Ό μ ννκ² μ§μ ν©λλ€.
> speech_response.json: λͺ λ Ή μ€ν κ²°κ³Όλ₯Ό speech_response.json νμΌμ μ μ₯ν©λλ€.
π νμ€ν¬ 4. Translation APIλ‘ ν μ€νΈ λ²μ
μ΄ νμ€ν¬μμλ μΌλ³Έμ΄ λ¬Έμ₯μ μμ΄λ‘ λ²μν©λλ€.
λ€μ curl λͺ λ Ήμ΄λ₯Ό μ¬μ©νμ¬ Cloud Translation APIλ₯Ό νΈμΆνκ³ , κ²°κ³Όλ₯Ό translated_response.txt νμΌμ μ μ₯ν©λλ€.
Bash
| curl -s -X POST -H “Content-Type: application/json” \ -H “Authorization: Bearer $(gcloud auth print-access-token)” \ “https://translation.googleapis.com/language/translate/v2” \ -d ‘{ “q”: “γγγ―ζ₯ζ¬θͺγ§γγ”, “target”: “en” }’ > translated_response.txt |
“q”: λ²μν ν μ€νΈμ λλ€.
“target”: λ²μν λͺ©ν μΈμ΄ μ½λ(enμ μμ΄)μ λλ€.
β νμ€ν¬ 5. Translation APIλ‘ μΈμ΄ κ°μ§
μ΄ νμ€ν¬μμλ μ£Όμ΄μ§ λ¬Έμ₯μ΄ μ΄λ€ μΈμ΄μΈμ§ κ°μ§ν©λλ€.
λ€μ curl λͺ λ Ήμ΄λ₯Ό μ¬μ©νμ¬ Cloud Translation APIμ μΈμ΄ κ°μ§ μλν¬μΈνΈλ₯Ό νΈμΆνκ³ , κ²°κ³Όλ₯Ό detection_response.txt νμΌμ μ μ₯ν©λλ€.
Bash
curl -s -X POST -H “Content-Type: application/json” \
-H “Authorization: Bearer $(gcloud auth print-access-token)” \
“https://translation.googleapis.com/language/translate/v2/detect” \
-d ‘{
“q”: “Este Γ© japonΓͺs.”
}’ > detection_response.txt
“q”: μΈμ΄λ₯Ό κ°μ§ν ν μ€νΈμ λλ€. μ΄ λ¬Έμ₯μ ν¬λ₯΄ν¬κ°μ΄λ‘ “μ΄κ²μ μΌλ³Έμ΄μ λλ€.”λΌλ λ»μ λλ€.
μ΄ κ°μ΄λκ° μ±λ¦°μ§ λ©μ μ±κ³΅μ μΌλ‘ μλ£νλ λ° ν° λμμ΄ λκΈ°λ₯Ό λ°λλλ€! λͺ¨λ λ¨κ³λ₯Ό μμλλ‘ λ°λΌ νμκ³ , λͺ λ Ήμ΄λ₯Ό μ λ ₯ν λ μ€νκ° μλμ§ λ€μ νλ² νμΈνμΈμ.
μ 보
μ리_μ§κ΅¬
μ§μ₯μΈλΌμ΄ν
νμ΄μ¬
GA4λΆμ