TTSHelper - GachonCapstoneTeam/TTS_JAVA GitHub Wiki
π£οΈ TTSHelper
TTSHelper
λ Google Cloud Text-to-Speech APIλ₯Ό ν΅ν΄ ν
μ€νΈλ₯Ό μμ±(MP3 νμΌ)μΌλ‘ λ³ννκ³ , μ±μ μ€λμ€ μ¬μ νλ¦μ ν΅ν©νκΈ° μν μ νΈλ¦¬ν° ν΄λμ€μ
λλ€.
β μ£Όμ κΈ°λ₯ μμ½
κΈ°λ₯ | μ€λͺ |
---|---|
ν μ€νΈ β μμ± λ³ν | Google TTS APIλ₯Ό μ¬μ©ν΄ ν μ€νΈλ₯Ό MP3 μ€λμ€ νμΌλ‘ λ³ν |
μ€λμ€ νμΌ μΊμ± | λ³νλ MP3λ μΊμ λλ ν 리μ μ μ₯νμ¬ μ¬μμ² λ°©μ§ |
λ³ν μλ£ μ½λ°± μ 곡 | λ³νμ΄ μλ£λλ©΄ μ½λ°± μΈν°νμ΄μ€λ‘ μλ¦Ό |
κΈ°λ³Έ μμ± μ¬μ μ§μ | ν μ€νΈμ© κΈ°λ³Έ MP3κ° μ‘΄μ¬ν κ²½μ° λ°λ‘ μ¬μ κ°λ₯ |
μ€ν¨ μ Toast μλ΄ | μλ¬ λ°μ μ μ¬μ©μμκ² Toastλ‘ νΌλλ°± μ 곡 |
π§ μ£Όμ λ‘μ§ μ€λͺ
π ν μ€νΈλ₯Ό TTS μμ²μΌλ‘ λ³ν
data.put("input", new JSONObject().put("text", text));
data.put("voice", new JSONObject().put("languageCode", "ko-KR"));
data.put("audioConfig", new JSONObject().put("audioEncoding", "MP3"));
- JSON ννλ‘ Google TTS APIμ μμ²ν λ°μ΄ν°λ₯Ό ꡬμ±ν©λλ€.
π μ΄λ―Έ μ‘΄μ¬νλ μ€λμ€ νμΌ νμΈ
if (audioFile.exists()) {
listener.onAudioFileReady(audioFile);
return;
}
- λμΌν νμΌ μ΄λ¦μ΄ μ΄λ―Έ μΊμμ μ‘΄μ¬νλ©΄ API νΈμΆ μμ΄ μ¦μ μ¬μ κ°λ₯νλλ‘ μ²λ¦¬ν©λλ€.
π μ€λμ€ νμΌ μ μ₯
byte[] decodedAudio = Base64.decode(audioContentEncoded, Base64.DEFAULT);
try (FileOutputStream fos = new FileOutputStream(audioFile)) {
fos.write(decodedAudio);
listener.onAudioFileReady(audioFile);
}
- TTS μλ΅μμ λ°μ Base64 μΈμ½λ©λ μμ±μ λμ½λ© ν MP3 νμΌλ‘ μ μ₯ν©λλ€.
π κ΄λ ¨ ν΄λμ€ λ° μ¬μ© μμΉ
AudioService
: μ€λμ€ μ¬μ μ²λ¦¬ReportAdapter
λ°HomeFragment
μμ μ¬μ©λμ΄ TTS κ²°κ³Όλ₯Ό μ¬μ
β οΈ μ°Έκ³ :
TTSHelper
ν΄λμ€λGoogle Cloud TTS API ν€
κ° νμνλ©°, μ¬μ©λμ λ°λΌ λΉμ©μ΄ μ²κ΅¬λ μ μμ΅λλ€.