Skip to content
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

2641 change audio emotion/speed management #2644

Merged
merged 29 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bce1769
2508: fix and switch on job which clear unused pictures
Jun 5, 2023
1c3f867
2508: fix and switch on job which clear unused pictures
Jun 7, 2023
f11db5b
Merge branch 'master' of https://github.com/Brain-up/brn into master
Jun 8, 2023
57bd061
Merge branch 'master' of https://github.com/Brain-up/brn into master
Jul 14, 2023
71dfe6a
Merge branch 'master' of https://github.com/Brain-up/brn into master
Sep 13, 2023
0b63d7b
Merge branch 'master' of https://github.com/Brain-up/brn into master
Oct 20, 2023
fd7b24e
Merge branch 'master' of https://github.com/Brain-up/brn into master
Oct 27, 2023
d071187
Merge branch 'master' of https://github.com/Brain-up/brn into master
Nov 8, 2023
55b12e0
Merge branch 'master' of https://github.com/Brain-up/brn into master
Nov 29, 2023
c21af0d
Merge branch 'master' of https://github.com/Brain-up/brn into master
Nov 29, 2023
323919c
Merge branch 'master' of https://github.com/Brain-up/brn into master
Nov 30, 2023
3fe1ceb
Merge branch 'master' of https://github.com/Brain-up/brn into master
Jan 17, 2024
86a6719
Merge branch 'master' of https://github.com/Brain-up/brn into master
Jan 18, 2024
0242323
Merge branch 'master' of https://github.com/Brain-up/brn into master
Feb 17, 2024
6efc270
Merge branch 'master' of https://github.com/Brain-up/brn into master
Jun 5, 2024
ba9485b
Merge branch 'master' of https://github.com/Brain-up/brn into master
Jun 6, 2024
685afb0
Merge branch 'master' of https://github.com/Brain-up/brn into master
Jul 30, 2024
e07f371
Merge branch 'master' of https://github.com/Brain-up/brn into master
Aug 10, 2024
93a1ca8
Merge branch 'master' of https://github.com/Brain-up/brn into master
Aug 19, 2024
1315a60
Merge branch 'master' of https://github.com/Brain-up/brn into master
Sep 27, 2024
d61cc3f
Merge branch 'master' of https://github.com/Brain-up/brn into master
Oct 4, 2024
97db0f0
2590 fix version update
Oct 4, 2024
723a145
Merge branch 'master' of https://github.com/Brain-up/brn into master
Oct 9, 2024
31de7c5
Merge branch 'master' of https://github.com/Brain-up/brn into master
Oct 16, 2024
932a301
Merge branch 'master' of https://github.com/Brain-up/brn into master
Oct 18, 2024
45902ae
Merge branch 'master' of https://github.com/Brain-up/brn into master
Nov 14, 2024
8ba5f20
2641 change audio emotion/speed management
Nov 15, 2024
29e6569
Merge branch 'master' of https://github.com/Brain-up/brn into 2641
Nov 15, 2024
c8f96fe
2641 change audio emotion/speed management
Nov 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/kotlin/com/epam/brn/dto/AudioFileMetaData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@ data class AudioFileMetaData(
this.speedCode = AzureRates.X_SLOW
this.speedFloat = "0.65"
}

fun setSpeedNormal() {
this.speedCode = AzureRates.DEFAULT
this.speedFloat = "1"
}

fun setSpeedFaster() {
this.speedCode = AzureRates.FAST
this.speedFloat = "1.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class YandexSpeechKitService(
@Value("\${yandex.format}")
lateinit var format: String

@Value("\${yandex.emotion}")
lateinit var emotion: String
@Value("\${yandex.emotions}")
lateinit var emotions: List<String>

var iamToken: String = ""
var iamTokenExpiresTime: LocalDateTime = LocalDateTime.now(ZoneOffset.UTC)
Expand Down Expand Up @@ -78,6 +78,7 @@ class YandexSpeechKitService(
*/
fun generateAudioStream(audioFileMetaData: AudioFileMetaData): InputStream {
val token = getYandexIamTokenForAudioGeneration()
val emotion = emotions.random()
val parameters = ArrayList<NameValuePair>().apply {
add(BasicNameValuePair("folderId", folderId))
add(BasicNameValuePair("lang", audioFileMetaData.locale))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,34 @@ class UserAnalyticsServiceImpl(
}

override fun prepareAudioStreamForUser(exerciseId: Long, audioFileMetaData: AudioFileMetaData): InputStream =
textToSpeechService.generateAudioOggStreamWithValidation(prepareAudioFileMetaData(exerciseId, audioFileMetaData))
textToSpeechService
.generateAudioOggStreamWithValidation(
prepareAudioFileMetaData(exerciseId, audioFileMetaData)
)

override fun prepareAudioFileMetaData(exerciseId: Long, audioFileMetaData: AudioFileMetaData): AudioFileMetaData {
val currentUserId = userAccountService.getCurrentUserId()
val lastExerciseHistory = studyHistoryRepository
.findLastByUserAccountIdAndExerciseId(currentUserId, exerciseId)
val seriesType = ExerciseType.valueOf(exerciseRepository.findTypeByExerciseId(exerciseId))

val text = audioFileMetaData.text
if (!listTextExercises.contains(seriesType))
audioFileMetaData.text = text.replace(" ", ", ")

if (text.contains(" ")) {
if (isDoneBad(lastExerciseHistory))
audioFileMetaData.setSpeedSlowest()
else
audioFileMetaData.setSpeedSlow()
} else if (isDoneBad(lastExerciseHistory)) {
if (lastExerciseHistory == null)
audioFileMetaData.setSpeedNormal()
else if (isDoneBad(lastExerciseHistory))
audioFileMetaData.setSpeedSlow()
}
else if (isDoneWell(lastExerciseHistory))
audioFileMetaData.setSpeedFaster()
return audioFileMetaData
}

fun isDoneBad(lastHistory: StudyHistory?): Boolean =
lastHistory != null && !exerciseService.isDoneWell(lastHistory)

fun isDoneWell(lastHistory: StudyHistory?): Boolean =
lastHistory != null && exerciseService.isDoneWell(lastHistory)

fun isMultiWords(seriesType: ExerciseType): Boolean =
seriesType == ExerciseType.PHRASES || seriesType == ExerciseType.SENTENCE || seriesType == ExerciseType.WORDS_SEQUENCES

Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ yandex.generationAudioLink=https://tts.api.cloud.yandex.net/speech/v1/tts:synthe
yandex.folderId=${YANDEX_FOLDER_ID:b1g0m877l9r22ngujisu}
yandex.format=oggopus
#yandex.emotion=good
yandex.emotion=neutral
yandex.speeds=0.8,1,1.2
yandex.emotions=neutral,good
yandex.folderForFiles=frontend/public

brn.picture.file.default.path=pictures/%s.jpg
Expand Down
36 changes: 26 additions & 10 deletions src/test/kotlin/com/epam/brn/service/UserAnalyticsServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ internal class UserAnalyticsServiceTest {
val metaDataResult = userAnalyticsService.prepareAudioFileMetaData(exerciseId, audioFileMetaData)

// THEN
metaDataResult.speedFloat shouldBe "0.8"
metaDataResult.speedCode shouldBe AzureRates.SLOW
metaDataResult.speedFloat shouldBe "1.2"
metaDataResult.speedCode shouldBe AzureRates.FAST
metaDataResult.text shouldBe "мама, папа"
}

Expand All @@ -152,8 +152,8 @@ internal class UserAnalyticsServiceTest {
val metaDataResult = userAnalyticsService.prepareAudioFileMetaData(exerciseId, audioFileMetaData)

// THEN
metaDataResult.speedFloat shouldBe "0.8"
metaDataResult.speedCode shouldBe AzureRates.SLOW
metaDataResult.speedFloat shouldBe "1.2"
metaDataResult.speedCode shouldBe AzureRates.FAST
metaDataResult.text shouldBe "мама папа"
}

Expand All @@ -174,8 +174,8 @@ internal class UserAnalyticsServiceTest {
val metaDataResult = userAnalyticsService.prepareAudioFileMetaData(exerciseId, audioFileMetaData)

// THEN
metaDataResult.speedFloat shouldBe "0.65"
metaDataResult.speedCode shouldBe AzureRates.X_SLOW
metaDataResult.speedFloat shouldBe "0.8"
metaDataResult.speedCode shouldBe AzureRates.SLOW
metaDataResult.text shouldBe "мама, папа"
}

Expand All @@ -196,8 +196,8 @@ internal class UserAnalyticsServiceTest {
val metaDataResult = userAnalyticsService.prepareAudioFileMetaData(exerciseId, audioFileMetaData)

// THEN
metaDataResult.speedFloat shouldBe "0.65"
metaDataResult.speedCode shouldBe AzureRates.X_SLOW
metaDataResult.speedFloat shouldBe "0.8"
metaDataResult.speedCode shouldBe AzureRates.SLOW
metaDataResult.text shouldBe "мама папа"
}

Expand All @@ -217,8 +217,8 @@ internal class UserAnalyticsServiceTest {
val metaDataResult = userAnalyticsService.prepareAudioFileMetaData(exerciseId, audioFileMetaData)

// THEN
metaDataResult.speedFloat shouldBe "1"
metaDataResult.speedCode shouldBe AzureRates.DEFAULT
metaDataResult.speedFloat shouldBe "1.2"
metaDataResult.speedCode shouldBe AzureRates.FAST
metaDataResult.text shouldBe "мама"
}

Expand All @@ -242,6 +242,22 @@ internal class UserAnalyticsServiceTest {
metaDataResult.speedCode shouldBe AzureRates.SLOW
}

@Test
fun `should prepareAudioFileMetaData normal speed for single word`() {
// GIVEN
every { userAccountService.getCurrentUserId() } returns currentUserId
every {
studyHistoryRepository.findLastByUserAccountIdAndExerciseId(currentUserId, exerciseId)
} returns null
every { exerciseRepository.findTypeByExerciseId(exerciseId) } returns ExerciseType.SINGLE_SIMPLE_WORDS.name
val audioFileMetaData = AudioFileMetaData("text", BrnLocale.RU.locale, Voice.FILIPP.name, "1", AzureRates.DEFAULT)
// WHEN
val metaDataResult = userAnalyticsService.prepareAudioFileMetaData(exerciseId, audioFileMetaData)
// THEN
metaDataResult.speedFloat shouldBe "1"
metaDataResult.speedCode shouldBe AzureRates.DEFAULT
}

@Test
fun `should prepareAudioStreamForUser`() {
// GIVEN
Expand Down
3 changes: 1 addition & 2 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ yandex.getTokenLink=https://iam.api.cloud.yandex.net/iam/v1/tokens
yandex.generationAudioLink=https://tts.api.cloud.yandex.net/speech/v1/tts:synthesize
yandex.folderId=b1gqn2760f5ongt82lm3
yandex.format=oggopus
yandex.emotion=good
yandex.speeds=1,1.2
yandex.emotions=good
yandex.folderForFiles=audioTest

brn.resources.default-pictures.path=pictures/
Expand Down
Loading