Showing posts with label Text. Show all posts
Showing posts with label Text. Show all posts

03 April 2026

How can I convert a text file into an audio file without internet access on ubuntu?

$ pip install piper-tts

 

Since you installed it via pip, you can use the piper command directly in your terminal. Because Piper is a "neural" text-to-speech engine, it doesn't come with voices built-in; you have to provide a model file (.onnx) and its configuration file (.json).

Here is the workflow to convert your text file:

1. Get a Voice Model

If you haven't already, download a voice from the official repository. You need both files for a specific voice (e.g., en_US-lessac-medium.onnx and en_US-lessac-medium.onnx.json).

2. The Conversion Command

To convert a text file (let's call it input.txt) into an audio file (output.wav), use the following syntax:

Bash
piper --model /path/to/voice.onnx < input.txt --output_file output.wav

3. Practical Example

If your text file is named script.txt and your model is in the same folder, run:

Bash
cat script.txt | piper --model en_US-lessac-medium.onnx --output_file speech.wav

Pro Tips for Better Usage

  • Adjusting Speed: Use the --length_scale flag. A higher number makes it slower, a lower number makes it faster.

    • Example (Slower): --length_scale 1.5

  • Adding Pause/Sentence Gap: Use the --sentence_silence flag to add seconds of silence between sentences.

    • Example: --sentence_silence 0.5

  • Batch Processing: If you want to listen to the file immediately without saving it, you can pipe it to a player like aplay (built-in to Ubuntu):

    Bash
    cat script.txt | piper --model en_US-lessac-medium.onnx --output-raw | aplay -r 22050 -f S16_LE -t raw
    

Quick Note: If you get a "command not found" error, your pip script folder might not be in your PATH. You can usually fix this by running python3 -m piper instead of just piper at the start of the command.

Do you have a specific voice or language in mind, or are you looking for recommendations on the best-sounding models?

 

Sorry, I open the page, but can not find en_US-lessac-medium.onnx and en_US-lessac-medium.onnx.json

 

# Download the .onnx model file
wget -O en_US-lessac-medium.onnx "https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_US/lessac/medium/en_US-lessac-medium.onnx?download=true"

# Download the .json config file
wget -O en_US-lessac-medium.onnx.json "https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_US/lessac/medium/en_US-lessac-medium.onnx.json?download=true"

 

# Download the .onnx model file (approx. 114MB)
wget -O en_GB-cori-high.onnx "https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_GB/cori/high/en_GB-cori-high.onnx?download=true"

# Download the .json config file
wget -O en_GB-cori-high.onnx.json "https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_GB/cori/high/en_GB-cori-high.onnx.json?download=true"

 

Run the conversion

Once those are finished, use this command to convert your text file (e.g., input.txt) to a UK-voiced audio file:

Bash
cat input.txt | piper --model en_GB-cori-high.onnx --output_file uk_speech.wav

Other UK Options

Gemini, could you give me the commands for downloading some other GB voice models, please? Thank you!
 

Here are the commands for some of the most popular British (UK) voice models available for Piper. Each model has a slightly different personality and quality level.

1. Alan (Male - Medium Quality)

This is a standard, clear male British voice.

Bash
# Model
wget -O en_GB-alan-medium.onnx "https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_GB/alan/medium/en_GB-alan-medium.onnx?download=true"

# Config
wget -O en_GB-alan-medium.onnx.json "https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_GB/alan/medium/en_GB-alan-medium.onnx.json?download=true"

2. Southern English Female (Female - Low Quality)

Despite being "low" quality, it is very fast and efficient, with a distinct southern accent.

Bash
# Model
wget -O en_GB-southern_english_female-low.onnx "https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_GB/southern_english_female/low/en_GB-southern_english_female-low.onnx?download=true"

# Config
wget -O en_GB-southern_english_female-low.onnx.json "https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_GB/southern_english_female/low/en_GB-southern_english_female-low.onnx.json?download=true"

3. VCTK (Multi-speaker - Medium Quality)

The VCTK model is unique because it contains dozens of different British speakers in one file. You can switch between them using the --speaker flag (e.g., --speaker 0, --speaker 1, etc.).

Bash
# Model
wget -O en_GB-vctk-medium.onnx "https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_GB/vctk/medium/en_GB-vctk-medium.onnx?download=true"

# Config
wget -O en_GB-vctk-medium.onnx.json "https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_GB/vctk/medium/en_GB-vctk-medium.onnx.json?download=true"

How to use them

Just swap the model name in your command. For example, to use the Alan voice:

Bash
cat temp03.txt | piper --model en_GB-alan-medium.onnx --output_file output_alan.wav

Pro Tip: Automating the check

Since you've had issues with corrupted downloads before, you can run this quick "check" after downloading to see if the file is valid:

Bash
# This will show the size; Alan should be ~15MB, VCTK ~45MB
ls -lh *.onnx

If you ever want to try a Northern English accent, there is also a northern_english_male model available—just let me know and I'll grab those links for you!

 

Yes, please. Thank you!

 

The Northern English voice is a great choice—it has a very distinct, warm character compared to the standard "Received Pronunciation" (London-style) voices.

Here are the commands for the Northern English Male model (Medium quality):

1. Download the Northern English Voice Files

Bash
# Download the .onnx model file (approx. 63MB)
wget -O en_GB-northern_english_male-medium.onnx "https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_GB/northern_english_male/medium/en_GB-northern_english_male-medium.onnx?download=true"

# Download the .json config file
wget -O en_GB-northern_english_male-medium.onnx.json "https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_GB/northern_english_male/medium/en_GB-northern_english_male-medium.onnx.json?download=true"

2. Run the conversion

Use this command to hear the new accent:

Bash
cat temp03.txt | piper --model en_GB-northern_english_male-medium.onnx --output_file northern_uk.wav

A Quick Tip for Your Setup

Since you've downloaded several voices now, your folder might be getting a bit crowded. You can verify all your available models at once with:

Bash
ls -lh *.onnx

Common Model Sizes for Comparison:

  • Cori (High): ~114 MB

  • Northern English (Medium): ~63 MB

  • Alan (Medium): ~15 MB

If any of these files show a size of only a few KB, they didn't download correctly—just delete that specific file and run the wget command for it again.

Enjoy the new voice! It’s one of the more unique ones in the British collection.

 

01 September 2025

How to extract texts from an image on ubuntu?

To extract English texts - 
$ sudo apt install tesseract-ocr
$ tesseract your_image_name.png extracted_text.txt 

 

To extract Simplified Chinese texts -

$ sudo apt install tesseract-ocr tesseract-ocr-chi-sim

$ tesseract your_image.tiff output_text.txt -l chi_sim

 

To extract Traditional Chinese texts -

$ sudo apt install tesseract-ocr tesseract-ocr-chi-tra

$ tesseract your_image.tiff output_text.txt -l chi_tra

 

To extract multiple languages, e.g. English and Simplified Chinese, and Traditional Chinese texts -

$ tesseract your_image.tiff output_text.txt -l eng+chi_sim+chi_tra

16 September 2023

Copy text from pictures on Linux with Textsnatcher

https://www.addictivetips.com/ubuntu-linux-tips/copy-text-from-pictures-on-linux-with-textsnatcher/

$ sudo apt install flatpak

$ sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

$sudo flatpak install flathub com.github.rajsolai.textsnatcher


Step 1: With Textsnatcher open, find the “Snatch Now!” button and click on it with the mouse. After selecting this button, Textsnatcher should open up the default screenshot tool for your Linux desktop.

Note: if you use Gnome or a Gnome-based desktop environment, it will launch the Gnome screenshot tool.

Step 2: With the screenshot tool open, find the “Select an area to grab” option and click on it with the mouse. When you select this button, the screenshot tool will allow you to take a screenshot of a selected area on the desktop.

Step 3: After you’ve selected the “select an area to grab” option, your mouse cursor will become a cross icon. Click and drag over the area you wish to extract text from.

Step 4: Once you’ve selected an area on the desktop with the cursor, the screenshot tool will take a picture. It will open up a dialog box that says, “Share this screenshot with TextSnatcher?”

Select the “Share” button to share the screenshot to Textsnatcher so that it can extract the text contents of the image.

Step 5: With the screenshot exported to Textsnatcher, you should see a message that says “Checkout Clipboard.” From here, go to a text editor (or any other text field) and press Ctrl + V hotkey to paste the text.

13 January 2022

How to automatically break long lines if lines are too long in vim?

To break long lines,

:set textwidth=78

To prevent a line from being broken from within a word,

:set linebreak

27 July 2021

How to concatenate all the text files in a directory with Python?

 How to concatenate all the text files in a directory with Python?


https://stackoverflow.com/questions/13613336/python-concatenate-text-files

import glob2

filenames = glob2.glob('*.txt')  # list of all .txt files in the directory

with open('outfile.txt', 'w') as f:
    for file in filenames:
        with open(file) as infile:
            f.write(infile.read()+'\n')

01 July 2021

How to find all the files containing the string 'abc' in the current directory and all the sub-directories

How to find all the files containing the string 'abc' in the current directory and all the sub-directories?


find . -type f | xargs fgrep '...'

26 October 2016

Texts in PDF Files not Selectable

Texts in PDF files are not selectable. How to convert them into selectable files?

Steps of Solution:

1. Open it with Adobe Reader.
2. File | Print. Select 'Adobe PDF' as printer.
3. Click Properties | Adobe PDF Settings.
4. In 'Default Settings' selection box, choose 'High Quality Print'. Click OK. Click Print.
5. In 'Paper/Quality' tab, click Advanced...
6. For 'Print quality', choose 1200dpi.
7. Enter a file name, and save it.


1. Open the saved file with Adobe Acrobat.
2. Open Tools.
3. Go to 'Action Wizard'. Under 'Actions', choose 'Make Accessible'.
4. Click 'Start'.
5. In Description popup dialogue box, you can choose whether to fill in information. Click 'OK'.
6. In Recognize Text popup box, click OK.
7. In Fillable Form popup box, you can choose to click Yes or No.
8. In Reading Language popup box, click OK.
9. In Alternative Text for Image popup box, click OK.
10. In Set Alternative Text, click 'Save & Close'.
11. In 'Accessibility Checker Options' popup box, click 'Start checking'. Go above and click 'Close'.
12. Go to top right-hand corner, click Close.
13. Save the file as another file name.
Done.

09 September 2015

How Do You Make Text-Selectable PDF files From Photoshop?

How Do You Make Text-Selectable PDF files From Photoshop?

Do not flatten layers or merge visible layers (keep the layers separate), then you can get a text-selectable PDF file from Photoshop.

14 May 2015

Chinese Characters are Displayed as Question Marks

Chinese Characters are Displayed as Question Marks


Cause: You have saved the Chinese text file in ANSI encoding.

Solution: Save the Chinese text file in Unicode encoding.

05 January 2015

Email message in Outlook is plain text (or not see images) instead of html

Tools | Trust Centre | Email Security | Read as Plain Text,
Clear the tick in front of 'Read all standard mail in plain text'.

08 December 2014

How to copy Chinese and English texts from a photo PDF file?

Adobe Acrobat
Tools | Text Recognition | In this file | Edit | Priamary OCR Language,

Choose Chinese, then English will also be OK.

30 June 2014

Wrap text around an image with CSS

http://www.homeandlearn.co.uk/WD/wds4p6.html

Let's see how to get the following style:
Browser showing text wrapped around an image
As you can see, the image is on the right and the text flows around it. There is also space between the image and the text.
The first thing to do is to set up a STYLE in the HEAD section of the HTML. Add the highlighted code to your own HTML:
CSS style for text wrapping
The style we've set up is called TextWrap. In between the two curly brackets we have this:
float: right;
margin: 10px;
The CSS property we need in order to move the image is called float. The float property can take three values: left, right and none. To get some space between the image and the text we can use the margin property. We've set it to 10 pixels. This will give you space around the entire image. If you only want space on specific sides of the image you can use these:
margin-left
margin-right
margin-top
margin-bottom
So we could have done this:
margin-left: 10px;
margin-bottom: 10px;
That would get us a 10 pixels margin on the left of the image and 10 pixels at the bottom.
To apply the style to the image, you need to add the CLASS attribute to the IMG tag:
<IMG SRC="york_images/york_minster_2.gif" CLASS="TextWrap">
The CLASS attribute doesn't have to go at the end. If you prefer, you can put it after the IMG tag:
<IMG CLASS="TextWrap" SRC="york_images/york_minster_2.gif" >
Just take note of where all the spaces are in the code above.
Amend your own IMG tag and add CLASS="TextWrap" to your own IMG code. Before you try it out, add a paragraph of text below the image:
<IMG class="TextWrap" SRC="york_images/york_minster_2.gif">
<P>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed at ante. Mauris eleifend, quam a vulputate dictum, massa quam dapibus leo, eget vulputate orci purus ut lorem. In fringilla mi in ligula. Pellentesque aliquam quam vel dolor. Nunc adipiscing. Sed quam odio, tempus ac, aliquam molestie, varius ac, tellus. Vestibulum ut nulla aliquam risus rutrum interdum. Pellentesque lorem. Curabitur sit amet erat quis risus feugiat viverra.
</P>
You can, of course, use your own text, and not just the Lorem ipsum text. Make sure your IMG code is above the first P tag, however.
Save your work and view the results in your browser.
There is, however, a problem with the above code. Suppose we want a second paragraph of text with another image floated on the left. We want to do this:
Browser showing text wrapped around two images
Here, the second image is nicely aligned below and to the left of the first image. The text is in the right place, too.
To achieve this, you might think of adding a second style and then applying it to the second image. Like this:
CSS code that wraps text to the left and right of two images
In the second style, we've used float: left and added a 10 pixel margin as before. In the second IMG tag, we've used the new TextWrapLeft class.
However, saving the work and refreshing gives you this in the browser:
Browser showing badly aligned text wrapping
In this version, the second image starts two thirds of the way down the first image. The text doesn't flow as we want it, as well.
The way to correct this is to use a CSS property called clear. This clears any floating elements and gets you back to the normal, default flow for browsers. The clear property can take four values: left, right, both, none. Because our first image was floated to the right, we want to clear to the right. We can add this to the second style:
CSS code that clears text wrapping
If our first image had been on the left, we would have used clear: left.