我的语音到文本视图不工作,我有wav文件,但我得到了这个错误
Traceback (most recent call last):
File "C:\Users\privet01\Desktop\python projects\projex x\myvev\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\privet01\Desktop\python projects\projex x\myvev\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\privet01\Desktop\python projects\projex x\alpha1\appsolve\views.py", line 636, in spechtotext
with sr.AudioFile(sound) as source:
File "C:\Users\privet01\Desktop\python projects\projex x\myvev\lib\site-packages\speech_recognition\__init__.py", line 236, in __enter__
raise ValueError("Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another format")
ValueError: Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another format
[23/Aug/2021 13:26:44] "POST /spechtotext/ HTTP/1.1" 500 152359
这是我的观点
import speech_recognition as sr
from django.core.files.storage import FileSystemStorage
def spechtotext(request) :
if request.method=='POST':
if request.FILES['theFileINEEd'] and '.mp3' in str(request.FILES['theFileINEEd'].name).lower() :
myfile = request.FILES['theFileINEEd']
fs = FileSystemStorage('')
filename = fs.save(str(request.user)+"speachtotext.WAV", myfile)
file_url = fs.url(filename)
full_link='http://127.0.0.1:8000'+file_url # changeble to life mode
r = sr.Recognizer()
print(type(filename))
print('hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh')
r = sr.Recognizer()
import sys
print(sys.version_info)
print('qqqqqqqqqqqqqqqqqqqqqqqqq'+str(filename)+'aaaaaaaaaaaaaaaaaaaa')
hellow=sr.AudioFile(str(filename))
sound = str(filename)
with sr.AudioFile(sound) as source:
r.adjust_for_ambient_noise(source)
print("Converting Audio To Text ..... ")
audio = r.listen(source)
try:
print("Converted Audio Is : \n" + r.recognize_google(audio))
except Exception as e:
print("Error {} : ".format(e) )
audio_text = r.listen(source)
try:
# using google speech recognition
text = r.recognize_google(audio_text)
print('Converting audio transcripts into text ...')
print("this is the text : ",text)
except:
print('Sorry.. run again...')
return render (request,'appsolve/spechtotext.html',{'l5arij':request.FILES['theFileINEEd'],'link':file_url,'fulllink':full_link})
else:
return render (request,'appsolve/spechtotext.html',{'problem':"you must upload a file mp3"})
else:
return render (request,'appsolve/spechtotext.html',)
这是网页中的错误
这是已经在同一路径中的文件 我试着用mp3和PCM
我试着用清晰的声音 但没有任何更改相同的错误音频文件无法读取为PCM WAV
目前没有回答
相关问题 更多 >
编程相关推荐