Reputation: 71
I am trying to create srt file from my audio. Actually, I am following this tutorial for this. But when I am running the command python3 speech2srt.py --storage_uri gs://subtitlingsc/en.wav
it is showing the following error:
Transcribing gs://subtitlingsc/en.wav ...
Traceback (most recent call last):
File "speech2srt.py", line 152, in <module>
main()
File "speech2srt.py", line 146, in main
subs = long_running_recognize(args)
File "speech2srt.py", line 44, in long_running_recognize
operation = client.long_running_recognize(config, audio)
TypeError: long_running_recognize() takes from 1 to 2 positional arguments but 3 were given
If someone could help in solving this!
Link for speech2srt.py file.
Upvotes: 0
Views: 425
Reputation: 4075
This is happening due to the fact that you are providing the arguments config and audio which should be both keyword arguments. To solve the problem, you can replace client.long_running_recognize(config, audio)
with client.long_running_recognize(config = config, audio = audio)
As you can confirm here, the function long_running_recognize has the definition below:
async long_running_recognize(
request: google.cloud.speech_v1.types.cloud_speech.LongRunningRecognizeRequest = None,
*,
config: google.cloud.speech_v1.types.cloud_speech.RecognitionConfig = None,
audio: google.cloud.speech_v1.types.cloud_speech.RecognitionAudio = None,
retry: google.api_core.retry.Retry = <object object>,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = ()
)
In Python, a function definition with arguments like (arg1, arg2, * , arg3, agr4, ...) means that only the arguments before the * can be provided as positional arguments. Being this the case, all the arguments after the * should be provided as keyword arguments.
As an example, lets create a function with the arguments I mentioned:
def function(arg1, arg2, * , arg3, agr4):
pass
If I try to call this function as function(1,2,3,4)
, it will fail because only two positional arguments are needed. To call it correctly I should provide two positional arguments and two keyword arguments therefore the correct call should be function(1, 2, arg3 = 3, arg4 = 4)
Upvotes: 1