mirror of
https://github.com/hwanny1128/HGZero.git
synced 2025-12-06 17:16:25 +00:00
- 회의시작및실시간회의록작성.puml 병합 완료 - .gitignore 업데이트 - stt-ai 디렉토리 추가 - requirements.txt, .env.example 추가 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
136 lines
4.4 KiB
Python
136 lines
4.4 KiB
Python
"""
|
|
Azure Speech SDK 연결 테스트
|
|
- 마이크 입력을 받아 실시간 STT 수행
|
|
- 화자 식별 기능 테스트
|
|
"""
|
|
|
|
import os
|
|
import azure.cognitiveservices.speech as speechsdk
|
|
from dotenv import load_dotenv
|
|
|
|
# .env 파일 로드
|
|
load_dotenv()
|
|
|
|
def test_azure_speech_connection():
|
|
"""Azure Speech 서비스 연결 테스트"""
|
|
|
|
# 환경변수에서 키 읽기
|
|
speech_key = os.getenv("AZURE_SPEECH_KEY")
|
|
speech_region = os.getenv("AZURE_SPEECH_REGION")
|
|
|
|
if not speech_key or not speech_region:
|
|
print("❌ 환경변수가 설정되지 않았습니다!")
|
|
print(" .env 파일에 AZURE_SPEECH_KEY와 AZURE_SPEECH_REGION을 설정하세요.")
|
|
return False
|
|
|
|
print(f"🔑 Azure Speech Key: {speech_key[:10]}...")
|
|
print(f"🌍 Region: {speech_region}")
|
|
|
|
# Speech Config 생성
|
|
speech_config = speechsdk.SpeechConfig(
|
|
subscription=speech_key,
|
|
region=speech_region
|
|
)
|
|
speech_config.speech_recognition_language = "ko-KR"
|
|
|
|
# 오디오 설정 (마이크)
|
|
audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)
|
|
|
|
# Recognizer 생성
|
|
recognizer = speechsdk.SpeechRecognizer(
|
|
speech_config=speech_config,
|
|
audio_config=audio_config
|
|
)
|
|
|
|
print("\n🎤 마이크에 대고 말씀하세요 (한국어)...")
|
|
print(" (음성 인식이 시작됩니다)\n")
|
|
|
|
try:
|
|
# 한 번의 음성 인식 수행
|
|
result = recognizer.recognize_once()
|
|
|
|
if result.reason == speechsdk.ResultReason.RecognizedSpeech:
|
|
print(f"✅ 인식 성공!")
|
|
print(f"📝 텍스트: {result.text}")
|
|
return True
|
|
elif result.reason == speechsdk.ResultReason.NoMatch:
|
|
print(f"⚠️ 음성을 인식하지 못했습니다.")
|
|
print(f" 세부정보: {result.no_match_details}")
|
|
return False
|
|
elif result.reason == speechsdk.ResultReason.Canceled:
|
|
cancellation = result.cancellation_details
|
|
print(f"❌ 인식 취소됨: {cancellation.reason}")
|
|
if cancellation.reason == speechsdk.CancellationReason.Error:
|
|
print(f" 에러 코드: {cancellation.error_code}")
|
|
print(f" 에러 메시지: {cancellation.error_details}")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ 예외 발생: {e}")
|
|
return False
|
|
|
|
|
|
def test_continuous_recognition():
|
|
"""연속 음성 인식 테스트 (실시간 스트리밍)"""
|
|
|
|
speech_key = os.getenv("AZURE_SPEECH_KEY")
|
|
speech_region = os.getenv("AZURE_SPEECH_REGION")
|
|
|
|
speech_config = speechsdk.SpeechConfig(
|
|
subscription=speech_key,
|
|
region=speech_region
|
|
)
|
|
speech_config.speech_recognition_language = "ko-KR"
|
|
|
|
audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)
|
|
recognizer = speechsdk.SpeechRecognizer(
|
|
speech_config=speech_config,
|
|
audio_config=audio_config
|
|
)
|
|
|
|
print("\n🔄 연속 음성 인식 테스트 시작...")
|
|
print(" (Ctrl+C로 종료하세요)\n")
|
|
|
|
# 이벤트 핸들러
|
|
def recognized_handler(evt):
|
|
if evt.result.reason == speechsdk.ResultReason.RecognizedSpeech:
|
|
print(f"✅ [{evt.result.offset/10000000:.1f}s] {evt.result.text}")
|
|
|
|
def canceled_handler(evt):
|
|
print(f"❌ 취소됨: {evt}")
|
|
|
|
# 이벤트 연결
|
|
recognizer.recognized.connect(recognized_handler)
|
|
recognizer.canceled.connect(canceled_handler)
|
|
|
|
# 연속 인식 시작
|
|
recognizer.start_continuous_recognition()
|
|
|
|
try:
|
|
# 사용자가 종료할 때까지 대기
|
|
input("Press Enter to stop...\n")
|
|
except KeyboardInterrupt:
|
|
print("\n⏹️ 인식 중지 중...")
|
|
finally:
|
|
recognizer.stop_continuous_recognition()
|
|
print("✅ 연속 인식 종료")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("=" * 60)
|
|
print("🎤 Azure Speech SDK 연결 테스트")
|
|
print("=" * 60)
|
|
|
|
# 1. 기본 연결 테스트
|
|
print("\n[테스트 1] 기본 음성 인식")
|
|
success = test_azure_speech_connection()
|
|
|
|
if success:
|
|
# 2. 연속 인식 테스트
|
|
response = input("\n연속 인식 테스트를 진행하시겠습니까? (y/n): ")
|
|
if response.lower() == 'y':
|
|
test_continuous_recognition()
|
|
|
|
print("\n" + "=" * 60)
|
|
print("테스트 완료!")
|
|
print("=" * 60) |