解决语音的识别和转换兼容性

This commit is contained in:
zwssunny
2023-03-27 16:53:59 +08:00
parent b3cb81aa52
commit 24de670c2c
3 changed files with 37 additions and 83 deletions

View File

@@ -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')