当我用带有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)