@@ -126,26 +126,13 @@ struct ExampleCommand: ParsableCommand {
126126 /// Run the transcription process.
127127 ///
128128 /// - Throws: An error from `TranscribeError`.
129- func transcribe( ) async throws {
130- // Convert the value of the `--format` option into the Transcribe
131- // Streaming `MediaEncoding` type.
132-
133- let mediaEncoding : TranscribeStreamingClientTypes . MediaEncoding
134- switch format {
135- case . flac:
136- mediaEncoding = . flac
137- case . ogg:
138- mediaEncoding = . oggOpus
139- case . pcm:
140- mediaEncoding = . pcm
141- }
142-
129+ func transcribe( encoding: TranscribeStreamingClientTypes . MediaEncoding ) async throws {
143130 // Create the Transcribe Streaming client.
144131
145132 // snippet-start:[swift.transcribe-streaming.StartStreamTranscription]
146133 let client = TranscribeStreamingClient (
147134 config: try await TranscribeStreamingClient . TranscribeStreamingClientConfiguration (
148- region: region
135+ region: region
149136 )
150137 )
151138
@@ -155,7 +142,7 @@ struct ExampleCommand: ParsableCommand {
155142 input: StartStreamTranscriptionInput (
156143 audioStream: try await createAudioStream ( ) ,
157144 languageCode: TranscribeStreamingClientTypes . LanguageCode ( rawValue: lang) ,
158- mediaEncoding: mediaEncoding ,
145+ mediaEncoding: encoding ,
159146 mediaSampleRateHertz: sampleRate
160147 )
161148 )
@@ -200,6 +187,26 @@ struct ExampleCommand: ParsableCommand {
200187 }
201188 }
202189 // snippet-end:[swift.transcribe-streaming]
190+
191+ /// Convert the value of the `--format` command line option into the
192+ /// corresponding Transcribe Streaming `MediaEncoding` type.
193+ ///
194+ /// - Returns: The `MediaEncoding` equivalent of the format specified on
195+ /// the command line.
196+ func getMediaEncoding( ) -> TranscribeStreamingClientTypes . MediaEncoding {
197+ let mediaEncoding : TranscribeStreamingClientTypes . MediaEncoding
198+
199+ switch format {
200+ case . flac:
201+ mediaEncoding = . flac
202+ case . ogg:
203+ mediaEncoding = . oggOpus
204+ case . pcm:
205+ mediaEncoding = . pcm
206+ }
207+
208+ return mediaEncoding
209+ }
203210}
204211
205212// -MARK: - Entry point
@@ -212,7 +219,7 @@ struct Main {
212219
213220 do {
214221 let command = try ExampleCommand . parse ( args)
215- try await command. transcribe ( )
222+ try await command. transcribe ( encoding : command . getMediaEncoding ( ) )
216223 } catch let error as TranscribeError {
217224 print ( " ERROR: \( error. errorDescription ?? " Unknown error " ) " )
218225 } catch {
0 commit comments