오늘은 파이썬에서 STT를 사용하기에 가장 편리한 SpeechRecognition 라이브러리 각 api별로 호출하는 걸 살펴보겠다.
많은 api를 가지고 있고, 각 모델마다 파라미터가 다르다보니 헷갈려서 정리하게 되었다.
GitHub - Uberi/speech_recognition: Speech recognition module for Python, supporting several engines and APIs, online and offline
Speech recognition module for Python, supporting several engines and APIs, online and offline. - GitHub - Uberi/speech_recognition: Speech recognition module for Python, supporting several engines ...
github.com
현재 마지막 버전은 3.10.0이며 파이썬 3.8,3.9,3.10을 지원한다고 한다.
또한 지원되는 모델들은 아래와 같으며, 추가적으로 반영되지 않은 pull request들에 Deepgram, assembly api 등들이 있으니 추후에 아래 링크에서 코드를 직접 수정하여 사용해도 좋을 것 같다.
Speech recognition 라이브러리 api 추가하기
오늘은 프로젝트에서 사용하는 speech recognition의 api 추가적인 api들이나 세부적인 사항들을 업데이트해보려고 한다. 우선 그냥 라이브러리를 다운받으면 되는거 아닌가? 할텐데 그게 아니라, githu
changsroad.tistory.com
우선 내가 사용하는 것들 위주로 사용법을 알아보도록 하자.
사실 자세한 사용법은 github에 있지만, 매번 찾기 귀찮기 때문에~~
# 마이크 입력 STT
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
# 저장된 음성파일 STT
import speech_recognition as sr
r = sr.Recognizer()
audio_file = sr.AudioFile('tmp.wav')
with audio_file as source:
audio = r.record(source)
위에서 마이크로 입력 후 바로 테스트 할 때와, 저장된 음성파일로 테스트할 때 위의 코드를 복사하고, 아래 각 api별로 호출하면서 테스트해보면 된다.
요약
모델명 | 사전설치 필요 | API 필요 | 한국어 지원 | 내 사용 여부 | PULL_REQUEST |
Google cloud speech | X | O(유료) | O | X | X |
Wit | X | O(유료,어플생성) | ? | X | X |
Microsoft Azure Speech | X | O(12개월무료?) | O | X | X |
Houndify | X | O(유료?) | X | X | X |
Assembly ai | X | O(유료) | O | X | O |
IBM Speech to Text | X | O(500분 무료/달) | O | X | X |
Whisper | O | X | O | O | O |
Whisper api | X | O(유료) | O | X | X |
Vosk | O | X | O | O | O |
Google speech Recognition | X | O(무료,내장) | O | O | X |
기본 내장 API
[Google speech Recognition]
api키를 발급받아야하나, 기본 내장된 api가 있어서, 그냥 바로 사용 가능하다.
API Keys
API Keys If there are features which use Google APIs that you need for a custom build, fork, or integration of stock Chromium. If you are building ChromiumOS yourself, as API access is required for login. Note: Software distribution with keys acquired for
www.chromium.org
What are language codes in Chrome's implementation of the HTML5 speech recognition API?
Chrome implemented the HTML5 speech recognition API. Many languages are supported. I wanna know which languages are supported and each language's corresponding code which is used in the HTML elemen...
stackoverflow.com
[Google Cloud Speech API]
# recognize_google_cloud(self, audio_data, credentials_json=None, language="en-US", preferred_phrases=None, show_all=False):
GOOGLE_CLOUD_SPEECH_CREDENTIALS = r"""INSERT THE CONTENTS OF THE GOOGLE CLOUD SPEECH JSON CREDENTIALS FILE HERE"""
print(r.recognize_google_cloud(audio, credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS,language='ko-KR'))
우선 api 키를 발급받아야 한고, 한국어를 사용하려면 ko-KR로 지정해줘야하고 더 많은 언어지원은 아래 더보기에 있다.
빠른 시작 | Cloud Speech-to-Text 문서 | Google Cloud
의견 보내기 빠른 시작 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. 의견 보내기 달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0
cloud.google.com
Speech-to-Text 지원 언어 | Cloud Speech-to-Text 문서 | Google Cloud
의견 보내기 Speech-to-Text 지원 언어 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. 이 페이지에는 Cloud Speech-to-Text에서 지원하는 모든 언어가 나와 있습니다.
cloud.google.com
[Wit.ai]
API키를 발급받아야하는데, 그러려면 wit계정을 만들고 무슨 어플을 만들어야한다고 한다. 또한 language는 앱설정에서 가능하다고 해서 난 pass
# recognize_wit(self, audio_data, key, show_all=False):
WIT_AI_KEY = "INSERT WIT.AI API KEY HERE"
print(r.recognize_wit(audio, key=WIT_AI_KEY))
[Microsoft Azure Speech]
이 또한 api키를 발급받아야하며, api 발급 사이트와 지원언어 리스트는 더보기에 있다.
Speech to Text - 오디오를 텍스트로 변환 | Microsoft Azure
데이터 관리를 위한 통합 데이터 거버넌스 서비스인 Microsoft Purview를 다운로드하세요. 온-프레미스, 다중 클라우드, SaaS(Software as a Service) 데이터를 관리하고 제어하세요.
azure.microsoft.com
Language support - Speech service - Azure AI services
The Speech service supports numerous languages for speech to text and text to speech conversion, along with speech translation. This article provides a comprehensive list of language support by service feature.
learn.microsoft.com
# recognize_azure(self, audio_data, key, language="en-US", profanity="masked", location="westus", show_all=False):
AZURE_SPEECH_KEY = "INSERT AZURE SPEECH API KEY HERE"
print(r.recognize_azure(audio, key=AZURE_SPEECH_KEY,language='ko-KR'))
[Houndify API]
아래에서 client id와 client key를 발급받아야하며, 영어만 지원한다고 하니 pass
# recognize_houndify(self, audio_data, client_id, client_key, show_all=False)
HOUNDIFY_CLIENT_ID = "INSERT HOUNDIFY CLIENT ID HERE"
HOUNDIFY_CLIENT_KEY = "INSERT HOUNDIFY CLIENT KEY HERE"
print("Houndify thinks you said " + r.recognize_houndify(audio, client_id=HOUNDIFY_CLIENT_ID, client_key=HOUNDIFY_CLIENT_KEY))
[assembly ai]
아래에서 api 토큰을 받으면 된다고한다. job_name은 어떤 내용을 출력할지? 뭐 최종 json 결과의 어떤 것을 출력할지 인것 같다. 자세한 설명이 되어있는 링크도 아래에 있다.
AssemblyAI | AI models to transcribe and understand speech
AssemblyAI is the fastest way to build with AI for audio. With a simple API, get access to production-ready AI models to transcribe and understand speech.
www.assemblyai.com
Speech Recognition | AssemblyAI Docs
Transcribe an audio file
www.assemblyai.com
# recognize_assemblyai(self, audio_data, api_token, job_name=None, **kwargs):
print(r.recognize_assemblyai(audio, api_token, job_name=None))
[IBM Speech to Text]
이것도 api를 발급받아야하고, language는 아래에서 설정가능하다.
#recognize_ibm(self, audio_data, key, language="en-US", show_all=False):
IBM_USERNAME = "INSERT IBM SPEECH TO TEXT USERNAME HERE"
IBM_PASSWORD = "INSERT IBM SPEECH TO TEXT PASSWORD HERE"
print(r.recognize_ibm(audio, username=IBM_USERNAME, password=IBM_PASSWORD,language=))
[Whisper]
로컬에 직접 whisper을 설치해야하며, 설치법 링크와 지원 언어모델은 더보기에 있다.
# recognize_whisper(self, audio_data, model="medium", show_dict=False, load_options=None, language=None, translate=False, device="cuda", **transcribe_options)
print(r.recognize_whisper(audio, language="ko-KR"))
[Whisper api]
OPENAI_API_KEY = "INSERT OPENAI API KEY HERE"
print(r.recognize_whisper_api(audio, api_key=OPENAI_API_KEY))
[Vosk]
사전 모델을 프로젝트 폴더에 model이라는 폴더를 만들고 거기다가 압축을 풀어놔야한다.
(pull request 글을 참고하면, 사전설치를 자동으로 해주는 코드있어용)
VOSK Offline Speech Recognition API
Accurate speech recognition for Android, iOS, Raspberry Pi and servers with Python, Java, C#, Swift and Node.
alphacephei.com
# 지원언어
{'ko', 'cn', 'fa', 'uz', 'en-gb', 'tr', 'ca', 'el-gr', 'pl', 'en-us', 'ua', 'kz', 'hi', 'sv', 'ru', 'de', 'es', 'cs', 'vn', 'all', 'nl', 'pt', 'tl-ph', 'ja', 'ar', 'br', 'it', 'fr', 'en-in', 'eo'}
print(r.recognize_vosk(audio,language='ko')) #-- 한글 언어 사용
추가로 뜯어보면 뭐 tensorflow도 있고, amazon도 있고 bing도있고 lex도 있었는데, 다들 공식 github에 소개가되어있지않아 deprecate된건가 싶어서 따로 안썻다.
위에 정리된 것들 중 뭐 이상한게 있다 싶으면 패키지의 __init__.py를 뜯어서 확인해보면 된다.
참고로 위에 나열된 것 중
Vosk, assemblyai, whisper, whisper api 는 pull request 요청된 것중 아직 더 발전된 코드가 있었고
새로운 api deepgram도 추가해놓은 pull request가 있었다. 자세한 수정법은 아래 블로그에 작성해놓았다.(아직 일부 미작성)
Speech recognition 라이브러리 api 추가하기
오늘은 프로젝트에서 사용하는 speech recognition의 api 추가적인 api들이나 세부적인 사항들을 업데이트해보려고 한다. 우선 그냥 라이브러리를 다운받으면 되는거 아닌가? 할텐데 그게 아니라, githu
changsroad.tistory.com
'프로젝트 > 음성비서' 카테고리의 다른 글
Speech recognition 라이브러리 api 추가하기 (0) | 2023.11.03 |
---|---|
업데이트 할 내용(Latest. Ver 4.0.1) (0) | 2023.11.03 |
Voice secretary 버전 4.0.1 (1) | 2023.11.03 |
Voice secretary 버전 3.0.1 (0) | 2023.11.03 |
Voice secretary 버전 3.0.0 (2) | 2023.11.02 |