Skip to content

Commit f0af182

Browse files
committed
Add back speed correctly
Signed-off-by: Lukas Schaefer <[email protected]>
1 parent 1227da9 commit f0af182

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/Service/OpenAiAPIService.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,12 +751,14 @@ public function getImageRequestOptions(?string $userId): array {
751751
* @param string $prompt
752752
* @param string $model
753753
* @param string $voice
754+
* @param int $speed
754755
* @return array
755756
* @throws Exception
756757
*/
757758
public function requestSpeechCreation(
758-
?string $userId, string $prompt, string $model, string $voice,
759+
?string $userId, string $prompt, string $model, string $voice, int $speed = 1,
759760
): array {
761+
$this->logger->error('speed is ' . $speed);
760762
if ($this->isQuotaExceeded($userId, Application::QUOTA_TYPE_SPEECH)) {
761763
throw new Exception($this->l10n->t('Speech generation quota exceeded'), Http::STATUS_TOO_MANY_REQUESTS);
762764
}
@@ -765,7 +767,8 @@ public function requestSpeechCreation(
765767
'input' => $prompt,
766768
'voice' => $voice === Application::DEFAULT_MODEL_ID ? Application::DEFAULT_SPEECH_VOICE : $voice,
767769
'model' => $model === Application::DEFAULT_MODEL_ID ? Application::DEFAULT_SPEECH_MODEL_ID : $model,
768-
'response_format' => 'wav'
770+
'response_format' => 'wav',
771+
'speed' => $speed,
769772
];
770773

771774
$apiResponse = $this->request($userId, 'audio/speech', $params, 'POST');

lib/TaskProcessing/TextToSpeechProvider.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public function getOptionalInputShape(): array {
7373
$this->l->t('The model used to generate the speech'),
7474
EShapeType::Enum
7575
),
76+
'speed' => new ShapeDescriptor(
77+
$this->l->t('Speed'),
78+
$this->l->t('Speech speed modifier'),
79+
EShapeType::Number
80+
)
7681
];
7782
}
7883

@@ -90,6 +95,7 @@ public function getOptionalInputShapeDefaults(): array {
9095
return [
9196
'voice' => $adminVoice,
9297
'model' => $adminModel,
98+
'speed' => 1,
9399
];
94100
}
95101

@@ -125,8 +131,13 @@ public function process(?string $userId, array $input, callable $reportProgress)
125131
$voice = $this->appConfig->getValueString(Application::APP_ID, 'default_speech_voice', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_SPEECH_VOICE;
126132
}
127133

134+
$speed = 1;
135+
if (isset($input['speed']) && is_numeric($input['speed'])) {
136+
$speed = $input['speed'];
137+
}
138+
128139
try {
129-
$apiResponse = $this->openAiAPIService->requestSpeechCreation($userId, $prompt, $model, $voice);
140+
$apiResponse = $this->openAiAPIService->requestSpeechCreation($userId, $prompt, $model, $voice, $speed);
130141

131142
if (!isset($apiResponse['body'])) {
132143
$this->logger->warning('OpenAI/LocalAI\'s text to speech generation failed: no speech returned');

0 commit comments

Comments
 (0)