如何解决当我使用带有getproperty的pyttsx3模块将pdf转换为文本或将文本转换为音频文件时出现ctype错误语音
当我用带有getproperty(语音)的pyttsx3模块将pdf转换为文本或将文本转换为音频文件时,出现以下错误
文件“ C:\ Users \ Sanjay \ AppData \ Local \ Programs \ Python \ Python36 \ lib \ site-packages \ pyttsx3 \ drivers \ sapi5.py”,第88行,在 返回[self._tts.GetVoices()中attr的[self._toVoice(attr)] _toVoice中的文件“ C:\ Users \ Sanjay \ AppData \ Local \ Programs \ Python \ Python36 \ lib \ site-packages \ pyttsx3 \ drivers \ sapi5.py”,第77行 返回Voice(attr.Id,attr.GetDescription()) _ctypes.COMError:(-2147200966,无,(无,无,无,0,无))
这是我的代码
serializer_class = DictionarySerializers
parser_classes = (FileUploadParser,MultiPartParser)
def post(self,request,*args,**kwargs):
file=fitz.open('dictpdf.pdf')
pages=len(file)
print(pages)
for pic in range(pages):
for image in file.getPageImageList(pic):
j=0
imageref=image[0]
pic_1=fitz.Pixmap(file,imageref)
final_pic=fitz.Pixmap(fitz.csRGB,pic_1)
# final_pic.writePNG(str(datetime.datetime.now())+".png")
final_pic.writePNG(str(pic) +"_" +str(j) + ".png")
pic = None
final_pic = None
j=j + 1
pdf = open('dictpdf.pdf','rb')
pdf_read_data = PyPDF2.PdfFileReader(pdf)
pages = pdf_read_data.numPages
print("pages",pages)
pagenum = pdf_read_data.getPage(0)
print("pagenum",pagenum)
text_data = pagenum.extractText()
file1 = open("dictionary.txt","a")
file1.writelines(text_data)
print("file",file1)
file1.close()
file = open("dictionary.txt",'r')
text = file.read()
print("new_text",text)
# return Response("hello")
word_list = text.split()
table = str.maketrans('','',string.punctuation)
stripped = [w.translate(table) for w in word_list]
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice',voices.id)
engine.setProperty('rate',120)
engine.setProperty('volume',1)
message=text_data
engine.say("Hello,This is text to audio")
engine.save_to_file(message,"+pdftotext ".mp3)
engine.runAndWait()
engine.stop()
return Response(status=status.HTTP_200_OK)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。