Let Obsidian read your text aloud

Original link: http://catcoding.me/p/obsidian-speech/

A simple and crude way to make writing better is to be your own reader, to constantly reread your own words, and to constantly revise them.

It’s not just about making words more readable, it’s a process of talking to oneself, Paul Graham writes in Putting Ideas into Words :

The real test is reading what you’ve written. You have to pretend to be a neutral reader who knows nothing of what’s in your head, only what you wrote. When he reads what you wrote, does it seem correct? Does it seem complete ? If you make an effort, you can read your writing as if you were a complete stranger, and when you do the news is usually bad. It takes me many cycles before I can get an essay past the stranger.

I am used to using the AI ​​voice of WeChat reading to listen to the book. Later, I found that WeChat reading can also subscribe to the public account, so I tried to use the AI ​​voice to read the articles I wrote aloud. It felt amazing, like asking someone else to read aloud.

We usually read it silently in our own minds after writing an article, but a real voice will make it easier to spot problems:

  • You will find your voice.
  • You will find mistakes and unnecessary words and sentences.
  • You will make your writing easy for reading.

So, I wrote an Obsidian plugin some time ago to implement the reading function, the code is here obsidian-speech

After I finished writing it, I wanted to submit it to the official plugin market, but then I found out that someone had already made a plugin with the same function, and then I didn’t want to submit it. But I still like my own implementation because there are some small optimizations in it.

Optimization 1: Automatically determine English paragraphs in the process of reading, because it will be inconsistent to read English aloud with Chinese voice. The logic of judgment is relatively simple, I think it is enough:

 async function getNextAudio ( sentence : string , code : string ) { let voice = speechSynthesis . getVoices ( ) . find ( v => v . name == code ) ; let audio = new SpeechSynthesisUtterance ( sentence ) ; let englishCharsCount = Array . from ( sentence ) . map ( c => ( c . match ( / [a-zA-Z] / ) ? 1 : 0 ) ) ; let englishCharsSum = englishCharsCount . reduce ( function ( sum , cur ) { return sum + cur } , 0 ) ; if ( englishCharsSum / sentence . length > 0.65 ) { voice = speechSynthesis . getVoices ( ) . find ( v => v . lang == "en-US" ) ; } if ( voice ) { audio . lang = voice . lang ; audio . voice = voice ; } window . speechSynthesis . speak ( audio ) ; return new Promise ( resolve => { audio . onend = resolve ; } ) ; } 

The second optimization is to highlight the paragraph that is being read aloud, so that you can quickly locate it.

However, the AI ​​voice quality in the Obsidian browser is obviously not as natural as in WeChat reading, and there are fewer types of voices supported. WeChat reading should have done a lot of optimization.

There are still a lot of places for this small plugin to continue to be refined, such as automatically skipping the embedded code part. If you are interested, let’s improve it together.

This article is reprinted from: http://catcoding.me/p/obsidian-speech/
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment

Your email address will not be published.