Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

04 July 2026

How to install Google Pinyin on Ubuntu 24.4

I want to install Google Pinyin on Ubuntu 24.4, but it says 'E: Unable to locate package fcitx5-googlepinyin'

The package fcitx5-googlepinyin does not exist. The original Google Pinyin engine (fcitx-googlepinyin) belongs to the legacy Fcitx 4 framework, which is no longer actively maintained.

On Ubuntu 24.04, the modern framework is Fcitx 5. Instead of a standalone Google Pinyin package, all Pinyin variants (along with a "Cloud Pinyin" feature that mimics Google's smart candidate suggestions) have been consolidated into a single package called fcitx5-chinese-addons.

Here is the correct, step-by-step method to install and configure it on Ubuntu 24.04.

Step 1: Install Fcitx 5 and the Chinese Addons

Open your terminal (Ctrl + Alt + T) and run the following command to update your package list and install Fcitx 5 along with its Chinese language engines:

Bash
sudo apt update
sudo apt install fcitx5 fcitx5-chinese-addons fcitx5-frontend-gtk3 fcitx5-frontend-qt5

Step 2: Set Fcitx 5 as the System Input Method

By default, Ubuntu uses the IBus framework. You need to tell the system to switch to Fcitx 5:

  1. Run the input method configuration tool:

    Bash
    im-config -n fcitx5
    
  2. For the changes to properly hook into your desktop environment (especially under Wayland/GNOME), log out of your Ubuntu session and log back in (or simply restart your computer).

Step 3: Configure Pinyin and Cloud Suggestions

Once you log back in, you can add the Pinyin keyboard and enable the smart cloud engine:

  1. Open your application launcher, search for Fcitx 5 Configuration (or run fcitx5-configtool in the terminal).

  2. Under the Input Method tab, click the + (Add) button.

  3. Uncheck “Only Show Current Language” if you are using an English system. Search for Pinyin, select it, and add it to your active input methods.

  4. To get the smart word predictions that Google Pinyin used to have, switch to the Addons tab in the configuration window.

  5. Look for Cloud Pinyin, click its configuration gear icon, and ensure it is enabled (you can set the cloud provider to Baidu or Google depending on your connectivity).

Step 4: Start Typing

You can now toggle between your standard keyboard layout and your new Pinyin layout using the default shortcut: Ctrl + Space.


Gemini is AI and can make mistakes.


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.

 

02 April 2026

How to find files? How to find directories?

How to find files? 

du -sk ./* | sort -nr

or 

du -sk ./* | grep -i "keyword" | sort -nr

or 

$ find . -maxdepth 1 -iname "*keyword*" -type f -printf "%T+ %p\n" | sort -r

or 

$ find . -maxdepth 1 -iname "*keyword*" -type f -exec du -sk {} + | sort -nr

 

How to find directories?

$ du -sk ./*/ | sort -nr

or

$ du -sk ./*/ | grep -i "keyword" | sort -nr 

or

$ find . -maxdepth 1 -iname "*keyword*" -type d -not -path '.' -printf "%T+ %p\n" | sort -r

or

$ find . -maxdepth 1 -iname "*keyword*" -type d -not -path '.' -exec du -sk {} + | sort -nr 

 

20 March 2026

How to find the most largest 10 files on Ubuntu?

To find the largest 10 files in a directory recursively on Ubuntu, use a combination of the
find, du, sort, and head commands.
Command to find the 10 largest files (human-readable format)
Run the following command in your terminal. Replace . with the specific directory path if you want to search a different location:
bash
find . -type f -exec du -Sh {} + | sort -rh | head -n 10
Explanation of the Command
Here is a breakdown of the commands and options used:
  • find .: Starts the search from the current directory (.) and traverses all subdirectories recursively.
  • -type f: Restricts the search to regular files only, ignoring directories, links, etc..
  • -exec du -Sh {} +: Executes the du command on the found files.
    • du: Estimates file space usage.
    • -S: Reports the size of individual files, not including the size of subdirectories (important for listing individual files correctly).
    • -h: Displays sizes in a human-readable format (e.g., 10MB, 2G).
    • {} and +: These are used by find to pass multiple filenames to a single du command efficiently.
  • |: Pipes the output of the find command to the sort command.
  • sort -rh: Sorts the output lines.
    • -r: Reverses the sort order, placing the largest files at the top.
    • -h: Compares human-readable numbers correctly (e.g., understands that 2G is larger than 10M).
  • | head -n 10: Displays only the first 10 lines of the sorted output (the top 10 largest files).
Alternative: Using Bytes for Precise Sorting
If you need a very precise numeric sort (e.g., if the human-readable sorting behaves unexpectedly on non-GNU systems), you can print sizes in bytes:
bash
find . -type f -printf "%s %p\n" | sort -nr | head -n 10
This command prints the size in bytes (%s) followed by the file path (%p), sorts numerically (-n) in reverse order (-r), and shows the top 10 results.
Interactive Method (GUI/TUI)
For an interactive, user-friendly experience, you can use the ncdu tool, which is available in the Ubuntu package manager.
  1. Install ncdu: sudo apt install ncdu.
  2. Run in the directory: ncdu . (or a specific path, e.g., ncdu /var/log). This provides an interactive interface to navigate directories and see the largest files and folders.

23 February 2026

Knowing port number, how to kill a process which is using that port?

  • Find what's sitting on the port:  

    $ sudo lsof -i :8000 (Replace 8000 with your port)

  • Kill that specific listener:  

    $ sudo kill -9 <PID_FROM_LSOF>


If I am running -

$ gunicorn --bind 0.0.0.0:8000 app:app
[2026-02-23 10:38:25 -0500] [250191] [INFO] Starting gunicorn 25.1.0
[2026-02-23 10:38:25 -0500] [250191] [INFO] Listening at: http://0.0.0.0:8000 (250191)
[2026-02-23 10:38:25 -0500] [250191] [INFO] Using worker: sync
[2026-02-23 10:38:25 -0500] [250191] [INFO] Control socket listening at /home/shermanchen/dev/convShop2/gunicorn.ctl
[2026-02-23 10:38:25 -0500] [250193] [INFO] Booting worker with pid: 250193

 

When I run lsof, I get -

$ sudo lsof -i :8000                           
COMMAND     PID        USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME                            
gunicorn 250191 shermanchen    3u  IPv4 1077472      0t0  TCP *:8000 (LISTEN)                 
gunicorn 250193 shermanchen    3u  IPv4 1077472      0t0  TCP *:8000 (LISTEN) 

 

If I kill the 'booting worker' pid 250193, the gunicorn will not be killed.  I have to kill the 'listening' pid 250191, to kill the gunicorn process.

$ sudo kill -9 250191

  

If I use ps, I got

$ ps aux | grep gunicorn                       
sherman+  250690  0.0  0.0   9824  2172 pts/1    S+   10:45   0:00 grep --color=auto gunicorn 
 

Killing pid 250690 will not kill the gunicorn process.

01 February 2026

How to crop a video on Ubuntu?

ffmpeg -i input.mp4 -vf "crop=1200:626:279:89" -c:v libx264 -crf 20 -c:a copy output.mp4


To crop a video on Ubuntu, you use FFmpeg’s
crop filter. Cropping is different from resizing; it’s like taking a pair of scissors to the video frame to cut out a specific area (like removing a watermark or focusing on a specific person).

The logic for cropping is: crop=width:height:x:y


1. The Basic Crop Command

If you know the exact dimensions you want to keep, use this:

Bash
ffmpeg -i input.mp4 -vf "crop=1280:720:0:0" -c:a copy output_cropped.mp4
  • 1280: The width of the "box" you want to keep.

  • 720: The height of the "box" you want to keep.

  • 0: The X coordinate (distance from the left edge) where the box starts.

  • 0: The Y coordinate (distance from the top edge) where the box starts.


2. Common "Real World" Examples

To crop a square from the center (great for social media):

Bash
ffmpeg -i input.mp4 -vf "crop=ih:ih" -c:a copy output_square.mp4

(Note: ih stands for "Input Height." This tells FFmpeg to make the width equal to the height.)

To cut the video in half (keep only the right side):

Bash
ffmpeg -i input.mp4 -vf "crop=iw/2:ih:iw/2:0" -c:a copy output_right_half.mp4

3. How to find your coordinates (The Easy Way)

Trying to guess "X" and "Y" coordinates in a terminal is hard. Here is a trick to do it visually:

  1. Open your video in VLC.

  2. Go to Tools > Effects and Filters.

  3. Go to Video Effects > Crop.

  4. Type in numbers until the video looks exactly how you want it.

  5. Write down those numbers (Left, Right, Top, Bottom) and use them in this FFmpeg command:

Bash
# If you found: Left=100, Top=50, Width=800, Height=600
ffmpeg -i input.mp4 -vf "crop=800:600:100:50" -c:a copy output_cropped.mp4

Important Tips:

  • Re-encoding: Because you are changing the actual picture, FFmpeg has to re-encode the video. I didn't include quality flags above to keep it simple, but for the best result, add -crf 20: ffmpeg -i input.mp4 -vf "crop=w:h:x:y" -c:v libx264 -crf 20 -c:a copy output.mp4

  • Even Numbers: Just like before, H.264 (MP4) loves even numbers. If you get an error, make sure your width and height are divisible by 2.