22# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
33# SPDX-License-Identifier: MIT
44
5+ import httpx
6+ import logging , verboselogs
57import json
68import logging , verboselogs
79
@@ -47,14 +49,15 @@ async def transcribe_url(
4749 source : UrlSource ,
4850 options : PrerecordedOptions = None ,
4951 addons : dict = None ,
52+ timeout : httpx .Timeout = None ,
5053 endpoint : str = "v1/listen" ,
5154 ) -> PrerecordedResponse :
5255 self .logger .debug ("PreRecordedClient.transcribe_url ENTER" )
5356
5457 if options is not None and options .callback is not None :
5558 self .logger .debug ("PreRecordedClient.transcribe_url LEAVE" )
5659 return await self .transcribe_url_callback (
57- source , options ["callback" ], options , addons , endpoint
60+ source , options ["callback" ], options , addons , timeout , endpoint
5861 )
5962
6063 url = f"{ self .config .url } /{ endpoint } "
@@ -72,7 +75,9 @@ async def transcribe_url(
7275 options = json .loads (options .to_json ())
7376 self .logger .info ("options: %s" , options )
7477 self .logger .info ("addons: %s" , addons )
75- result = await self .post (url , options = options , addons = addons , json = body )
78+ result = await self .post (
79+ url , options = options , addons = addons , json = body , timeout = timeout
80+ )
7681 self .logger .info ("json: %s" , result )
7782 res = PrerecordedResponse .from_json (result )
7883 self .logger .verbose ("result: %s" , res )
@@ -102,6 +107,7 @@ async def transcribe_url_callback(
102107 callback : str ,
103108 options : PrerecordedOptions = None ,
104109 addons : dict = None ,
110+ timeout : httpx .Timeout = None ,
105111 endpoint : str = "v1/listen" ,
106112 ) -> AsyncPrerecordedResponse :
107113 self .logger .debug ("PreRecordedClient.transcribe_url_callback ENTER" )
@@ -124,7 +130,9 @@ async def transcribe_url_callback(
124130 options = json .loads (options .to_json ())
125131 self .logger .info ("options: %s" , options )
126132 self .logger .info ("addons: %s" , addons )
127- result = await self .post (url , options = options , addons = addons , json = body )
133+ result = await self .post (
134+ url , options = options , addons = addons , json = body , timeout = timeout
135+ )
128136 self .logger .info ("json: %s" , result )
129137 res = AsyncPrerecordedResponse .from_json (result )
130138 self .logger .verbose ("result: %s" , res )
@@ -152,14 +160,15 @@ async def transcribe_file(
152160 source : FileSource ,
153161 options : PrerecordedOptions = None ,
154162 addons : dict = None ,
163+ timeout : httpx .Timeout = None ,
155164 endpoint : str = "v1/listen" ,
156165 ) -> PrerecordedResponse :
157166 self .logger .debug ("PreRecordedClient.transcribe_file ENTER" )
158167
159168 if options is not None and options .callback is not None :
160169 self .logger .debug ("PreRecordedClient.transcribe_file LEAVE" )
161170 return await self .transcribe_file_callback (
162- source , options ["callback" ], options , addons , endpoint
171+ source , options ["callback" ], options , addons , timeout , endpoint
163172 )
164173
165174 url = f"{ self .config .url } /{ endpoint } "
@@ -178,7 +187,9 @@ async def transcribe_file(
178187 options = json .loads (options .to_json ())
179188 self .logger .info ("options: %s" , options )
180189 self .logger .info ("addons: %s" , addons )
181- result = await self .post (url , options = options , addons = addons , content = body )
190+ result = await self .post (
191+ url , options = options , addons = addons , content = body , timeout = timeout
192+ )
182193 self .logger .info ("json: %s" , result )
183194 res = PrerecordedResponse .from_json (result )
184195 self .logger .verbose ("result: %s" , res )
@@ -208,6 +219,7 @@ async def transcribe_file_callback(
208219 callback : str ,
209220 options : PrerecordedOptions = None ,
210221 addons : dict = None ,
222+ timeout : httpx .Timeout = None ,
211223 endpoint : str = "v1/listen" ,
212224 ) -> AsyncPrerecordedResponse :
213225 self .logger .debug ("PreRecordedClient.transcribe_file_callback ENTER" )
@@ -231,7 +243,9 @@ async def transcribe_file_callback(
231243 options = json .loads (options .to_json ())
232244 self .logger .info ("options: %s" , options )
233245 self .logger .info ("addons: %s" , addons )
234- result = await self .post (url , options = options , addons = addons , json = body )
246+ result = await self .post (
247+ url , options = options , addons = addons , json = body , timeout = timeout
248+ )
235249 self .logger .info ("json: %s" , result )
236250 res = AsyncPrerecordedResponse .from_json (result )
237251 self .logger .verbose ("result: %s" , res )
0 commit comments