-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
157 additions
and
7 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
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
87 changes: 87 additions & 0 deletions
87
openai-core/src/commonMain/kotlin/com.aallam.openai.api/audio/SpeechRequest.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,87 @@ | ||
package com.aallam.openai.api.audio | ||
|
||
import com.aallam.openai.api.OpenAIDsl | ||
import com.aallam.openai.api.model.ModelId | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* Generates audio from the input text. | ||
*/ | ||
@Serializable | ||
public data class SpeechRequest( | ||
|
||
/** | ||
* One of the available TTS models: tts-1 or tts-1-hd | ||
*/ | ||
@SerialName("model") public val model: ModelId, | ||
|
||
/** | ||
* The text to generate audio for. The maximum length is 4096 characters. | ||
*/ | ||
@SerialName("input") public val input: String, | ||
|
||
/** | ||
* The voice to use when generating the audio | ||
*/ | ||
@SerialName("voice") public val voice: Voice? = null, | ||
|
||
/** | ||
* The format to audio in. | ||
*/ | ||
@SerialName("response_format") public val responseFormat: SpeechResponseFormat? = null, | ||
|
||
/** | ||
* The speed of the generated audio. Select a value from 0.25 to 4.0. 1.0 is the default. | ||
*/ | ||
@SerialName("speed") public val speed: Double? = null, | ||
) | ||
|
||
/** | ||
* Creates a new [SpeechRequest] instance. | ||
*/ | ||
public fun speechRequest(block: SpeechRequestBuilder.() -> Unit): SpeechRequest = | ||
SpeechRequestBuilder().apply(block).build() | ||
|
||
/** | ||
* A speech request builder. | ||
*/ | ||
@OpenAIDsl | ||
public class SpeechRequestBuilder { | ||
|
||
/** | ||
* One of the available TTS models: tts-1 or tts-1-hd | ||
*/ | ||
public var model: ModelId? = null | ||
|
||
/** | ||
* The text to generate audio for. The maximum length is 4096 characters. | ||
*/ | ||
public var input: String? = null | ||
|
||
/** | ||
* The voice to use when generating the audio | ||
*/ | ||
public var voice: Voice? = null | ||
|
||
/** | ||
* The format to audio in. | ||
*/ | ||
public var responseFormat: SpeechResponseFormat? = null | ||
|
||
/** | ||
* The speed of the generated audio. Select a value from 0.25 to 4.0. 1.0 is the default. | ||
*/ | ||
public var speed: Double? = null | ||
|
||
/** | ||
* Builds and returns a [SpeechRequest] instance. | ||
*/ | ||
public fun build(): SpeechRequest = SpeechRequest( | ||
model = requireNotNull(model) { "model is required" }, | ||
input = requireNotNull(input) { "input is required" }, | ||
voice = voice, | ||
responseFormat = responseFormat, | ||
speed = speed | ||
) | ||
} |
15 changes: 15 additions & 0 deletions
15
openai-core/src/commonMain/kotlin/com.aallam.openai.api/audio/SpeechResponseFormat.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,15 @@ | ||
package com.aallam.openai.api.audio | ||
|
||
import kotlinx.serialization.Serializable | ||
import kotlin.jvm.JvmInline | ||
|
||
@Serializable | ||
@JvmInline | ||
public value class SpeechResponseFormat(public val value: String) { | ||
public companion object { | ||
public val Mp3: SpeechResponseFormat = SpeechResponseFormat("mp3") | ||
public val Opus: SpeechResponseFormat = SpeechResponseFormat("opus") | ||
public val Aac: SpeechResponseFormat = SpeechResponseFormat("aac") | ||
public val Flac: SpeechResponseFormat = SpeechResponseFormat("flac") | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
openai-core/src/commonMain/kotlin/com.aallam.openai.api/audio/Voice.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,20 @@ | ||
package com.aallam.openai.api.audio | ||
|
||
import kotlinx.serialization.Serializable | ||
import kotlin.jvm.JvmInline | ||
|
||
/** | ||
* The voice to use when generating the audio | ||
*/ | ||
@Serializable | ||
@JvmInline | ||
public value class Voice(public val value: String) { | ||
public companion object { | ||
public val Alloy: Voice = Voice("alloy") | ||
public val Echo: Voice = Voice("echo") | ||
public val Fable: Voice = Voice("fable") | ||
public val Onyx: Voice = Voice("onyx") | ||
public val Nova: Voice = Voice("nova") | ||
public val Shimmer: Voice = Voice("shimmer") | ||
} | ||
} |