mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-06-02 00:57:41 +08:00
[voice] add google voice support
This commit is contained in:
21
voice/google/google_voice.py
Normal file
21
voice/google/google_voice.py
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
"""
|
||||
google voice service
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import speech_recognition
|
||||
from voice.voice import Voice
|
||||
|
||||
class GoogleVoice(Voice):
|
||||
recognizer = speech_recognition.Recognizer()
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def voiceToText(self, voice_file):
|
||||
new_file = voice_file.replace('.mp3', '.wav')
|
||||
subprocess.call('ffmpeg -i ' + voice_file + ' -acodec pcm_s16le -ac 1 -ar 16000 ' + new_file, shell=True)
|
||||
with speech_recognition.AudioFile(new_file) as source:
|
||||
audio = self.recognizer.record(source)
|
||||
return self.recognizer.recognize_google(audio, language='zh-CN')
|
||||
Reference in New Issue
Block a user