Skip to content

Commit e972786

Browse files
feat: apply speech & pitch real time
1 parent b87daf8 commit e972786

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

android/src/main/kotlin/project/pipepipe/app/ui/component/player/SpeedPitchDialog.kt

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ fun SpeedPitchDialog(
4141
var tempPitch by remember { mutableFloatStateOf(currentPitch) }
4242
var stepSize by remember { mutableFloatStateOf(0.25f) }
4343

44+
// Save initial values for cancel restoration
45+
val initialSpeed = remember { currentSpeed }
46+
val initialPitch = remember { currentPitch }
47+
4448
// Helper functions for non-linear slider mapping
4549
// Maps speed (0.1-10) to slider position (0-1) with 1x at center
4650
fun speedToSlider(speed: Float): Float {
@@ -93,7 +97,10 @@ fun SpeedPitchDialog(
9397
) {
9498
// Minus button
9599
OutlinedButton(
96-
onClick = { tempSpeed = (tempSpeed - stepSize).coerceIn(0.1f, 10f) },
100+
onClick = {
101+
tempSpeed = (tempSpeed - stepSize).coerceIn(0.1f, 10f)
102+
onApply(tempSpeed, tempPitch)
103+
},
97104
contentPadding = PaddingValues(vertical = 4.dp),
98105
modifier = Modifier.height(32.dp)
99106
) {
@@ -102,14 +109,20 @@ fun SpeedPitchDialog(
102109

103110
Slider(
104111
value = speedToSlider(tempSpeed),
105-
onValueChange = { tempSpeed = sliderToSpeed(it) },
112+
onValueChange = {
113+
tempSpeed = sliderToSpeed(it)
114+
onApply(tempSpeed, tempPitch)
115+
},
106116
valueRange = 0f..1f,
107117
modifier = Modifier.weight(1f)
108118
)
109119

110120
// Plus button
111121
OutlinedButton(
112-
onClick = { tempSpeed = (tempSpeed + stepSize).coerceIn(0.1f, 10f) },
122+
onClick = {
123+
tempSpeed = (tempSpeed + stepSize).coerceIn(0.1f, 10f)
124+
onApply(tempSpeed, tempPitch)
125+
},
113126
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 4.dp),
114127
modifier = Modifier.height(32.dp)
115128
) {
@@ -135,7 +148,10 @@ fun SpeedPitchDialog(
135148
) {
136149
// Minus button
137150
OutlinedButton(
138-
onClick = { tempPitch = (tempPitch - stepSize).coerceIn(0.1f, 10f) },
151+
onClick = {
152+
tempPitch = (tempPitch - stepSize).coerceIn(0.1f, 10f)
153+
onApply(tempSpeed, tempPitch)
154+
},
139155
contentPadding = PaddingValues(vertical = 4.dp),
140156
modifier = Modifier.height(32.dp)
141157
) {
@@ -144,14 +160,20 @@ fun SpeedPitchDialog(
144160

145161
Slider(
146162
value = speedToSlider(tempPitch),
147-
onValueChange = { tempPitch = sliderToSpeed(it) },
163+
onValueChange = {
164+
tempPitch = sliderToSpeed(it)
165+
onApply(tempSpeed, tempPitch)
166+
},
148167
valueRange = 0f..1f,
149168
modifier = Modifier.weight(1f)
150169
)
151170

152171
// Plus button
153172
OutlinedButton(
154-
onClick = { tempPitch = (tempPitch + stepSize).coerceIn(0.1f, 10f) },
173+
onClick = {
174+
tempPitch = (tempPitch + stepSize).coerceIn(0.1f, 10f)
175+
onApply(tempSpeed, tempPitch)
176+
},
155177
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 4.dp),
156178
modifier = Modifier.height(32.dp)
157179
) {
@@ -199,14 +221,20 @@ fun SpeedPitchDialog(
199221
onClick = {
200222
tempSpeed = 1.0f
201223
tempPitch = 1.0f
224+
onApply(tempSpeed, tempPitch)
202225
}
203226
) {
204227
Text(stringResource(MR.strings.playback_reset), fontSize = 14.sp)
205228
}
206229

207230
// Cancel and OK buttons on the right
208231
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
209-
TextButton(onClick = onDismiss) {
232+
TextButton(
233+
onClick = {
234+
onApply(initialSpeed, initialPitch)
235+
onDismiss()
236+
}
237+
) {
210238
Text(stringResource(MR.strings.cancel), fontSize = 14.sp)
211239
}
212240

0 commit comments

Comments
 (0)