-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from SWM-KAWAI-MANS/release/v1.2.0
Release/v1.2.0
- Loading branch information
Showing
9 changed files
with
170 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.VIBRATE" /> | ||
</manifest> |
68 changes: 68 additions & 0 deletions
68
core/common/src/main/java/online/partyrun/partyrunapplication/core/common/util/TTSManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package online.partyrun.partyrunapplication.core.common.util | ||
|
||
import android.content.Context | ||
import android.speech.tts.TextToSpeech | ||
import android.speech.tts.UtteranceProgressListener | ||
import java.util.Locale | ||
import java.util.UUID | ||
|
||
class TTSManager(context: Context, onInitSuccess: (TTSManager) -> Unit) { | ||
private var textToSpeech: TextToSpeech? = null | ||
|
||
init { | ||
textToSpeech = TextToSpeech(context) { status -> | ||
if (status == TextToSpeech.SUCCESS) { | ||
textToSpeech?.run { | ||
language = Locale.KOREA | ||
setSpeechRate(1.3f) | ||
onInitSuccess(this@TTSManager) | ||
} | ||
} | ||
} | ||
} | ||
|
||
/* | ||
* UUID를 사용하여 id를 고유하게 생성 -> 메시지를 연속으로 발화할 때 중복되는 utteranceId 문제 방지 | ||
*/ | ||
fun speak(text: String, shouldShutdownAfterSpeaking: Boolean = false) { | ||
val utteranceId = UUID.randomUUID().toString() | ||
if (shouldShutdownAfterSpeaking) { | ||
shutdownAfterSpeaking(utteranceId) | ||
} | ||
textToSpeech?.speak( | ||
text, | ||
TextToSpeech.QUEUE_ADD, | ||
null, | ||
utteranceId | ||
) | ||
} | ||
|
||
private fun shutdownAfterSpeaking(utteranceId: String) { | ||
textToSpeech?.setOnUtteranceProgressListener(object : UtteranceProgressListener() { | ||
override fun onStart(utteranceId: String?) { | ||
// speaking | ||
} | ||
|
||
override fun onError(utteranceId: String?) { | ||
// speaking error | ||
} | ||
|
||
override fun onDone(expectedUtteranceId: String?) { | ||
if (expectedUtteranceId == utteranceId) { | ||
shutdown() | ||
} | ||
} | ||
}) | ||
} | ||
|
||
fun shutdown() { | ||
textToSpeech?.shutdown() | ||
textToSpeech = null | ||
} | ||
} | ||
|
||
fun speakTTS(context: Context, message: String) { | ||
TTSManager(context) { manager -> | ||
manager.speak(message, shouldShutdownAfterSpeaking = true) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...rc/main/java/online/partyrun/partyrunapplication/core/common/util/VibrateDeviceManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package online.partyrun.partyrunapplication.core.common.util | ||
|
||
import android.content.Context | ||
import android.os.Build | ||
import android.os.VibrationEffect | ||
import android.os.Vibrator | ||
import android.os.VibratorManager | ||
|
||
class VibrateDeviceManager(context: Context) { | ||
private val vibrator: Vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||
val vibratorManager = | ||
context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager | ||
vibratorManager.defaultVibrator | ||
} else { | ||
@Suppress("DEPRECATION") | ||
context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator | ||
} | ||
|
||
fun vibrateFor(time: Long) { | ||
vibrator.vibrate( | ||
VibrationEffect.createOneShot( | ||
time, | ||
VibrationEffect.DEFAULT_AMPLITUDE, | ||
) | ||
) | ||
} | ||
} | ||
|
||
fun vibrateSingle(context: Context) { | ||
val vibrator = VibrateDeviceManager(context) | ||
vibrator.vibrateFor(200) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters