Skip to content

Commit

Permalink
Feat: Get pronunciation info by GET request
Browse files Browse the repository at this point in the history
표준발음 변환기 사이트를 통해 입력한 텍스트 발음정보, 근거항을 가져오는 기능
사이트: http://pronunciation.cs.pusan.ac.kr/pronunc.htm
  • Loading branch information
Kimdoodle committed Sep 21, 2024
1 parent 46becb9 commit aede2bb
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 5 deletions.
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
packages=find_packages(where='src'),
package_dir={'': 'src'},
install_requires=[
'pandas>=1.3.5',
'numpy==1.26.4',
'pandas==1.3.5',
'openpyxl>=3.1.5',
'requests>=2.31.0',
'google-cloud-speech>=2.26.0',
Expand All @@ -25,6 +26,7 @@
'ffmpeg-python>=0.2.0',
'konlpy>=0.6.0',
'jamo>=0.4.1',
'beautifulsoup4==4.12.3',
],
data_files=[
('key', key_files),
Expand Down
2 changes: 1 addition & 1 deletion src/common/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import pandas as pd

from tuning_STT.expand import remove_duplication
from common.info import open_dialog
from tuning_STT.expand import remove_duplication


def merge_json(filename: str):
Expand Down
10 changes: 7 additions & 3 deletions src/speech/STT.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import pprint
import re
import wave
import pandas as pd

# from CLOVA_STT import stt_clova
import google.cloud.speech_v1p1beta1 as speech
import google.cloud.storage as storage
from convert import convert_audio_files, convert_text_data
from evaluate import remove_correct, evaluate_SER
from tuning_STT.expand import remove_duplication
from common.info import open_dialog

import sys

# STT
def transcribe_audio(file_path):
Expand Down Expand Up @@ -72,7 +72,11 @@ def STT_pipeline(askFolder=None, model='google', makeTrainData=None, evaluation=
askFolder = input("폴더를 선택할까요?(Y/N): ").strip().lower() == 'y'
if askFolder:
path = open_dialog(True)
suffix = path.name.split('_')[1]
try:
suffix = path.name.split('_')[1]
except:
print("폴더 경로 오류.")
sys.exit()
else:
path = open_dialog(False, filetypes=[("Audio files", "*.m4a *.mp3 *.wav")])
suffix = ''
Expand Down
76 changes: 76 additions & 0 deletions src/speech/baleum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import requests
from bs4 import BeautifulSoup
from common.info import open_dialog
import pandas as pd

def getPronunciation(text: str):
url = "http://pronunciation.cs.pusan.ac.kr/pronunc2.asp"

# 요청 파라미터
params = {
"text1": text.encode('euc-kr'),
"submit1": "%C8%AE%C0%CE%C7%CF%B1%E2"
}

# GET 요청을 보냅니다 (디코딩 없이 바로 사용)
response = requests.get(url, params=params)

# BeautifulSoup 객체 생성 (디코딩 없이 content를 파싱)
soup = BeautifulSoup(response.content, 'html.parser')

# "입력 어절" 텍스트를 포함하는 <td> 요소를 찾음
input_word_td = soup.find('td', string="입력 어절")

if not input_word_td:
print("입력 어절을 포함하는 테이블을 찾을 수 없습니다.")
return

# 해당 <td> 요소의 부모 테이블을 찾음
title_table = input_word_td.find_parent('table')

if not title_table:
print("제목 테이블을 찾을 수 없습니다.")
return

# 제목 테이블 다음에 나오는 첫 번째 데이터 테이블을 찾음
data_table = title_table.find_next_sibling('table')

if not data_table:
print("데이터 테이블을 찾을 수 없습니다.")
return

# 테이블에서 행 추출
rows = data_table.find_all('tr')

# 데이터 저장을 위한 리스트
data = []

# 각 행에서 '입력 어절', '변환 결과', '표준발음법 및 도움말'을 추출
for row in rows:
cols = row.find_all('td')
if len(cols) >= 3: # 최소 3개의 열이 있어야 함
# 각 셀의 텍스트를 euc-kr로 디코딩
input_word = cols[0].text.strip()
conversion_result = cols[1].text.strip()
help_info = cols[2].text.strip()

# 데이터 저장
data.append({
"입력 어절": input_word,
"변환 결과": conversion_result,
"표준발음법 및 도움말": help_info
})

# 데이터 출력
for row in data:
print(f"입력 어절: {row['입력 어절']}, 변환 결과: {row['변환 결과']}, 표준발음법 및 도움말: {row['표준발음법 및 도움말']}")


if __name__ == '__main__':
fp = open_dialog(False)
data = pd.read_excel(fp).drop_duplicates(subset=['User content'])

# 1. data각 문장에 대해 단어 분리(라이브러리 사용)
# 2. getPro..()함수를 사용하여 발음 가져오기 + 표준 발음 및 근거항 저장
# 3. 엑셀로 저장
# 4. 이미 처리된 엑셀파일에 추가한 열을 추가로 저장(원문 비교로 삽입)

0 comments on commit aede2bb

Please sign in to comment.