์ด ์ฑ๋ฆฐ์ง ๋ฉ์ ๋ชฉํ๋ 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”: ์ธ์ด๋ฅผ ๊ฐ์งํ ํ ์คํธ์ ๋๋ค. ์ด ๋ฌธ์ฅ์ ํฌ๋ฅดํฌ๊ฐ์ด๋ก “์ด๊ฒ์ ์ผ๋ณธ์ด์ ๋๋ค.”๋ผ๋ ๋ป์ ๋๋ค.
์ด ๊ฐ์ด๋๊ฐ ์ฑ๋ฆฐ์ง ๋ฉ์ ์ฑ๊ณต์ ์ผ๋ก ์๋ฃํ๋ ๋ฐ ํฐ ๋์์ด ๋๊ธฐ๋ฅผ ๋ฐ๋๋๋ค! ๋ชจ๋ ๋จ๊ณ๋ฅผ ์์๋๋ก ๋ฐ๋ผ ํ์๊ณ , ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํ ๋ ์คํ๊ฐ ์๋์ง ๋ค์ ํ๋ฒ ํ์ธํ์ธ์.