Skip to content

Commit

Permalink
Merge pull request #87 from Xewdy444/dev
Browse files Browse the repository at this point in the history
Removed ThreadPoolExecutor
  • Loading branch information
Xewdy444 authored Mar 18, 2024
2 parents 866001a + 35d3967 commit ff581da
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions playwright_recaptcha/recaptchav2/async_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,28 +287,25 @@ async def _convert_audio_to_text(self, audio_url: str) -> Optional[str]:
wav_audio = BytesIO()
mp3_audio = BytesIO(await response.body())

with ThreadPoolExecutor() as executor:
audio: AudioSegment = await loop.run_in_executor(
executor, AudioSegment.from_mp3, mp3_audio
)
audio: AudioSegment = await loop.run_in_executor(
None, AudioSegment.from_mp3, mp3_audio
)

await loop.run_in_executor(
executor, functools.partial(audio.export, wav_audio, format="wav")
)
await loop.run_in_executor(
None, functools.partial(audio.export, wav_audio, format="wav")
)

recognizer = speech_recognition.Recognizer()
recognizer = speech_recognition.Recognizer()

async with AsyncAudioFile(wav_audio, executor=executor) as source:
audio_data = await loop.run_in_executor(
executor, recognizer.record, source
)
async with AsyncAudioFile(wav_audio) as source:
audio_data = await loop.run_in_executor(None, recognizer.record, source)

try:
return await loop.run_in_executor(
executor, recognizer.recognize_google, audio_data
)
except speech_recognition.UnknownValueError:
return None
try:
return await loop.run_in_executor(
None, recognizer.recognize_google, audio_data
)
except speech_recognition.UnknownValueError:
return None

async def _click_checkbox(self, recaptcha_box: AsyncRecaptchaBox) -> None:
"""
Expand Down

0 comments on commit ff581da

Please sign in to comment.