|
7 | 7 | - [ImageGenerations](#imagegenerations) |
8 | 8 | - [Edits](#edits) |
9 | 9 | - [AudioTranscriptions](#audioTranscriptions) |
| 10 | +- [AudioTranslations](#audioTranslations) |
10 | 11 |
|
11 | 12 | ## ListModels |
12 | 13 |
|
@@ -308,4 +309,56 @@ try { |
308 | 309 | } catch (e: exception) { |
309 | 310 | // catch any error that may occurs on api call. |
310 | 311 | } |
| 312 | +``` |
| 313 | + |
| 314 | +## AudioTranslations |
| 315 | + |
| 316 | +The audioTranscriptions api is used to translates audio into English. |
| 317 | + |
| 318 | +### Swift |
| 319 | + |
| 320 | +```swift |
| 321 | +var yChat: YChat { |
| 322 | + YChatCompanion.shared.create(apiKey: "your-api-key") |
| 323 | +} |
| 324 | + |
| 325 | +guard let audioFileUrl = Bundle.main.url(forResource: "audio", withExtension: "m4a") else { |
| 326 | + print("Unable to find the audio file.") |
| 327 | + return |
| 328 | +} |
| 329 | + |
| 330 | +let audioData = try! Data(contentsOf: audioFileUrl) |
| 331 | + |
| 332 | +do { |
| 333 | + let result = try await yChat.audioTranslations() |
| 334 | + .setModel(model: "whisper-1") |
| 335 | + .setPrompt(prompt: "") |
| 336 | + .setResponseFormat(format: "json") |
| 337 | + .setTemperature(temperature: 0.4) |
| 338 | + .execute(filename: "audio.m4a", audioFile: audioData) |
| 339 | +} catch { |
| 340 | + // catch any error that may occurs on api call. |
| 341 | +} |
| 342 | +``` |
| 343 | + |
| 344 | +### Kotlin |
| 345 | + |
| 346 | +```kotlin |
| 347 | +val yChat by lazy { |
| 348 | + YChat.create("your-api-key") |
| 349 | +} |
| 350 | + |
| 351 | +val inputStream = application.resources.openRawResource(R.raw.audio) |
| 352 | +val byteArray = inputStream.readBytes() |
| 353 | + |
| 354 | +try { |
| 355 | + val result = yChat.audioTranslations() |
| 356 | + .setModel("whisper-1") |
| 357 | + .setPrompt("") |
| 358 | + .setResponseFormat("json") |
| 359 | + .setTemperature(0.4) |
| 360 | + .execute("audio.m4a", byteArray) |
| 361 | +} catch (e: exception) { |
| 362 | + // catch any error that may occurs on api call. |
| 363 | +} |
311 | 364 | ``` |
0 commit comments