# Text to speech on selected text

**URL:** <https://pdfjs.community/t/text-to-speech-on-selected-text/1226>\
**Category:** Feature Requests\
**Tags:** pdfjs-express\
**Created:** [December 7, 2021, 4:14pm UTC](https://pdfjs.community/t/text-to-speech-on-selected-text/1226 "2021-12-07T16:14:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pesce88](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/pesce88/32/766_2.png) [@pesce88](https://pdfjs.community/u/pesce88)\
**Post date:** [December 7, 2021, 4:14pm UTC](https://pdfjs.community/t/text-to-speech-on-selected-text/1226/1 "2021-12-07T16:14:57Z")

</div>

If anyone is interested I have created a voice system for reading the selected text  
the new file webviewer-ui.js

> Speech = function() {  
> var e;  
> if (document.querySelector(“#copy-textarea”).value = “”, null === (e = window.getSelection()) || void 0 === e || !e.toString())  
> if (window.clipboardData) window.clipboardData.setData(“Text”, St.getSelectedText());  
> else {  
> var t = document.getElementById(“copy-textarea”);  
> aaa t.value = St.getSelectedText(), t.select(), t.setSelectionRange(0, 99999);  
> var msg = new SpeechSynthesisUtterance(t.value);  
> window.speechSynthesis.speak(msg);  
> }  
> }

this is a part of the code that I modified in the file
