본문 바로가기

RPA

[UiPath] 음성인식으로 reCaptcha 풀어보기 - 2

2편입니다..
굳이 Python을 활용하는 이유는... Google Speech를 사용할 것이기 때문입니다.
UiPath에도 Google Speech 패키지가 있지만 API키가 필요하고, 이걸 물어본 친구의 프로젝트에서는 API 키를 발급받을 수 없기 때문입니다....

사전 준비가 필요합니다.
1. .NET 5.0 SDK 설치
2. Python 설치
3. SpeechRecognition 설치
4. pydub 설치
5. ffmpeg 설정
6. UiPath Python 패키지 설치

1편보단 준비할 것이 좀 많습니다..

 

1. .NET 5.0 SDK 설치

Python Scope를 사용하기 위해서 필요합니다. UiPath Docs에서는 .NET Desktop Runtime 5.0.17을 설치해야한다고 합니다. 상위 버전은 호환이 안되니 5.0을 설치해주세요. SDK에는 Desktop Runtime이 포함되니 SDK 또는 Desktop Runtime을 설치해주시면 됩니다.

https://dotnet.microsoft.com/en-us/download/dotnet/5.0

 

Download .NET 5.0 (Linux, macOS, and Windows)

.NET 5.0 downloads for Linux, macOS, and Windows. .NET is a free, cross-platform, open-source developer platform for building many different types of applications.

dotnet.microsoft.com

https://docs.uipath.com/activities/docs/python-scope

 

Python Scope

UiPath.Python.Activities.PythonScope A container which provides a scope for Python activities and initializes the specified Python environment. When the Python Scope activity ends, all Python objects loaded up to that point are deleted. Properties Common D

docs.uipath.com

 

2. Python 설치

Python도 설치해주어야 합니다. 저는 3.6.8 사용 중입니다.

https://www.python.org/downloads/

 

Download Python

The official home of the Python Programming Language

www.python.org

 

 

3. SpeechRecognition 설치

음성인식에 필요한 패키지를 설치해줍니다. 이것때문에 .. 조금 고생했습니다. pip로 설치 가능합니다.
pip install SpeechRecognition==3.8.1

맨 처음 소스를 짤 때는 SpeechRecognition 버전이 3.8.1이었는데.. 디버깅을 하는 시점엔 패키지가 업데이트되면서 제가 사용하는 method의 return type이 변경된 것 같습니다... 소스를 수정할 수 있었지만 저는 그냥 패키지를 다운그레이드 하기로 했습니다...

제 소스 그대로 사용할 것이라면 SpeechRecognition은 3.8.1로 설치해주세요.

 

4. pydub 설치

mp3파일을 wav로 변경하기 위해 설치하는 패키지 입니다. pip로 설치 가능합니다.
pip install pydub

 

5. ffmpeg 설정

이 부분에서도 상당히 헤맸습니다..아래 블로그를 보고 설정을 했습니다.
다운로드 링크는 유효하지 않아서 아래 달아둡니다. ffmpeg-git-full.7z를 다운로드 받았고 나머지는 동일하게 진행했습니다.

https://www.gyan.dev/ffmpeg/builds/

 

Builds - CODEX FFMPEG @ gyan.dev

FFmpeg is a widely-used cross-platform multimedia framework which can process almost all common and many uncommon media formats. It has over 1000 internal components to capture, decode, encode, modify, combine, stream media, and it can make use of dozens o

www.gyan.dev

https://blog.gregzaal.com/how-to-install-ffmpeg-on-windows/

 

How to Install FFmpeg on Windows - Adaptive Samples

See how to install (and get started with) FFmpeg on Windows in this detailed guide with a crapton of screenshots.

blog.gregzaal.com

 

6. UiPath Python 패키지 설치

Python 스크립트 실행을 위해 설치해야 합니다. 1.6.0을 사용하면 .NET이 설치되지 않아도 오류 메세지도 출력되지 않으면서 멈춰있기만 하더라구요.. 그래서 저는 1.4.1을 사용하였습니다.

 

 

사용한 파이썬 코드입니다.

import speech_recognition as sr
import os
from pydub import AudioSegment
import sys

def main():
     path = "C:\\RPA\\SolveReCaptcha\\Data"
     filePath="C:\\RPA\\SolveReCaptcha\\Data\\audio.wav"
     os.chdir(path)
     audio_files = os.listdir()
     name, ext = os.path.splitext(filePath)
     if ext == ".mp3":
          mp3_sound = AudioSegment.from_file(filePath)
          mp3_sound.export("{0}.wav".format(name), format="wav")


     r = sr.Recognizer()

     harvard_audio = sr.AudioFile(name+".wav")

     with harvard_audio as source:
          audio = r.record(source)

     try:
          text = r.recognize_google(audio)
          return(text)

     except:
          return("Error")

결과입니다. 동일한 파일로 테스트한 것인데 결과가 다릅니다..
우선 Python으로 수행한 결과로 reCaptcha가 풀리는 것을 확인했습니다. 

SpeechRecognition 3.9.0 버전을 사용하면 return(text)를 했을 때 오류가 발생합니다.
3.8.1로 return하면 결과 텍스트만 출력되는데 3.9.0으로 return하면 아래와 같이 출력됩니다....

새벽까지 에러 잡다보니 도저히 소스 수정할 힘이 없어서 일단 다운그레이드해서 정상적으로 수행되는 것을 확인했습니다..... 나.....중에 위의 소스에 주석도 달아보고... 3.9.0으로도 수행가능하도록 소스 수정하겠습니다.....

Python +UiPath 프로젝트를 꼭 한 번 해보고 싶었는데.. 드디어 하네요....
끝입니다..~~

'RPA' 카테고리의 다른 글

[UiPath] 내가 자주 쓰는 거..  (2) 2023.11.30
[UiPath] xml 파일 다뤄보기  (2) 2023.09.13
[UiPath] 음성인식으로 reCaptcha 풀어보기 - 1  (2) 2023.02.18
[UiPath] Duplicate Column  (4) 2023.02.15
[UiPath] Activate가 안될 때  (3) 2022.11.16