Как реализовать преобразование текста в речь в PDF-файле, который уже загружен в pdfview
I'm trying to implement a text to speech in my application. First, I have implemented PDFview that allows me to pick PDF files from my device and load it. What I want to achieve is that after loading this PDF to the PDFview, I want to read the text out. How do I achieve this? using same Uri passed into my PDFView libabry to load the pdf so i can view it
Что я уже пробовал:
public String getRealPathFromURI(Context context, Uri contentURI) { String result; Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); if(cursor == null) { result = contentURI.getPath(); } else { cursor.moveToFirst(); int idx = cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA); result = cursor.getString(idx); cursor.close(); } return result; } btnSpeak.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String parsedText = ""; try { PdfReader pdfReader = new PdfReader(getRealPathFromURI(getContext(), uri)); int n = pdfReader.getNumberOfPages(); for (int i = 0; i < n; i++) { parsedText = parsedText + PdfTextExtractor.getTextFromPage(pdfReader, i + 1).trim() + "\n"; } pdfReader.close(); textToSpeech.speak(parsedText, TextToSpeech.QUEUE_FLUSH, null); } catch (Exception ex) { } } });