(
response: Result<OutputType<TModel>>,
)
| 111 | } |
| 112 | |
| 113 | private transformResponse( |
| 114 | response: Result<OutputType<TModel>>, |
| 115 | ): AudioGenerationResult { |
| 116 | const data = response.data as Record<string, unknown> |
| 117 | |
| 118 | // fal returns { audio: { url, content_type } } or { audio_url: string } |
| 119 | let audioUrl: string | undefined |
| 120 | let contentType: string | undefined |
| 121 | |
| 122 | if ( |
| 123 | data['audio'] && |
| 124 | typeof data['audio'] === 'object' && |
| 125 | 'url' in data['audio'] |
| 126 | ) { |
| 127 | const audioObj = data['audio'] as { url: string; content_type?: string } |
| 128 | audioUrl = audioObj.url |
| 129 | contentType = audioObj.content_type |
| 130 | } else if (typeof data.audio_url === 'string') { |
| 131 | audioUrl = data.audio_url |
| 132 | } |
| 133 | |
| 134 | if (!audioUrl) { |
| 135 | throw new Error('Audio URL not found in fal audio generation response') |
| 136 | } |
| 137 | |
| 138 | const usage = buildFalUsage(takeBillableUnits(response.requestId)) |
| 139 | |
| 140 | return { |
| 141 | id: response.requestId || this.generateId(), |
| 142 | model: this.model, |
| 143 | audio: { |
| 144 | url: audioUrl, |
| 145 | contentType: deriveAudioContentType(contentType, audioUrl), |
| 146 | }, |
| 147 | ...(usage ? { usage } : {}), |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | export function falAudio<TModel extends FalModel>( |
no test coverage detected