-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Text-To-Speech 구현 #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
minjun011026
wants to merge
2
commits into
main
Choose a base branch
from
feat/learnstt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -14,4 +14,5 @@ | |
.cxx | ||
local.properties | ||
.kotlin | ||
.idea | ||
.idea | ||
examplekey.jks |
This file contains hidden or 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
Binary file not shown.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
7 changes: 7 additions & 0 deletions
7
data/src/main/java/com/saegil/data/remote/TextToSpeechService.kt
This file contains hidden or 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,7 @@ | ||
package com.saegil.data.remote | ||
|
||
import java.io.File | ||
|
||
interface TextToSpeechService { | ||
suspend fun getAssistantAudio(text: String): File | ||
} |
27 changes: 27 additions & 0 deletions
27
data/src/main/java/com/saegil/data/remote/TextToSpeechServiceImpl.kt
This file contains hidden or 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,27 @@ | ||
package com.saegil.data.remote | ||
|
||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.request.accept | ||
import io.ktor.client.request.post | ||
import io.ktor.client.request.setBody | ||
import io.ktor.http.ContentType | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import java.io.File | ||
import javax.inject.Inject | ||
|
||
class TextToSpeechServiceImpl @Inject constructor( | ||
private val client: HttpClient | ||
) : TextToSpeechService { | ||
|
||
override suspend fun getAssistantAudio(text: String): File = withContext(Dispatchers.IO) { | ||
File.createTempFile("assistant_response", ".mp3").apply { | ||
writeBytes(client.post(HttpRoutes.TTS) { | ||
accept(ContentType.Application.OctetStream) | ||
setBody(mapOf("text" to text, "provider" to "OPENAI")) | ||
}.body()) | ||
} | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
data/src/main/java/com/saegil/data/repository/TextToSpeechRepositoryImpl.kt
This file contains hidden or 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,20 @@ | ||
package com.saegil.data.repository | ||
|
||
import com.saegil.data.remote.TextToSpeechService | ||
import com.saegil.domain.repository.TextToSpeechRepository | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.flowOn | ||
import java.io.File | ||
import javax.inject.Inject | ||
|
||
class TextToSpeechRepositoryImpl @Inject constructor( | ||
private val textToSpeechService: TextToSpeechService | ||
): TextToSpeechRepository { | ||
|
||
override suspend fun downloadAudio(text: String): Flow<File> = flow { | ||
emit(textToSpeechService.getAssistantAudio(text)) | ||
}.flowOn(Dispatchers.IO) | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
domain/src/main/java/com/saegil/domain/repository/TextToSpeechRepository.kt
This file contains hidden or 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,12 @@ | ||
package com.saegil.domain.repository | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import java.io.File | ||
|
||
interface TextToSpeechRepository { | ||
|
||
suspend fun downloadAudio( | ||
text: String | ||
): Flow<File> | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
domain/src/main/java/com/saegil/domain/usecase/DownloadAudioUseCase.kt
This file contains hidden or 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,14 @@ | ||
package com.saegil.domain.usecase | ||
|
||
import com.saegil.domain.repository.TextToSpeechRepository | ||
import kotlinx.coroutines.flow.Flow | ||
import java.io.File | ||
import javax.inject.Inject | ||
|
||
class DownloadAudioUseCase @Inject constructor( | ||
private val textToSpeechRepository: TextToSpeechRepository | ||
){ | ||
|
||
suspend operator fun invoke(text: String): Flow<File> = textToSpeechRepository.downloadAudio(text) | ||
|
||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The RecordButton onClick logic has been removed, which disables the functionality to start/stop recording. If this change is intentional to focus solely on TTS, please add a clarifying comment to explain the expected behavior.
Copilot uses AI. Check for mistakes.