mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-06-02 00:57:41 +08:00
解决语音的识别和转换兼容性
This commit is contained in:
@@ -3,17 +3,14 @@
|
||||
google voice service
|
||||
"""
|
||||
|
||||
import pathlib
|
||||
import subprocess
|
||||
import time
|
||||
from bridge.reply import Reply, ReplyType
|
||||
import speech_recognition
|
||||
import pyttsx3
|
||||
from gtts import gTTS
|
||||
from bridge.reply import Reply, ReplyType
|
||||
from common.log import logger
|
||||
from common.tmp_dir import TmpDir
|
||||
from voice.voice import Voice
|
||||
from voice.audio_convert import mp3_to_wav
|
||||
|
||||
|
||||
class GoogleVoice(Voice):
|
||||
@@ -30,11 +27,10 @@ class GoogleVoice(Voice):
|
||||
self.engine.setProperty('voice', voices[1].id)
|
||||
|
||||
def voiceToText(self, voice_file):
|
||||
new_file = voice_file.replace('.mp3', '.wav')
|
||||
# new_file = voice_file.replace('.mp3', '.wav')
|
||||
# subprocess.call('ffmpeg -i ' + voice_file +
|
||||
# ' -acodec pcm_s16le -ac 1 -ar 16000 ' + new_file, shell=True)
|
||||
mp3_to_wav(voice_file, new_file)
|
||||
with speech_recognition.AudioFile(new_file) as source:
|
||||
with speech_recognition.AudioFile(voice_file) as source:
|
||||
audio = self.recognizer.record(source)
|
||||
try:
|
||||
text = self.recognizer.recognize_google(audio, language='zh-CN')
|
||||
|
||||
Reference in New Issue
Block a user