Wednesday, 5 March 2025

Copy the music being played on the laptop with Ubuntu linux.

Step 1: Get the sink playing the audio.

Pulse audio command to list the applications which are currently using the laptop speakers. Returns the number which is used to record audio from.


$pactl list sink-inputs | grep -E 'Input #|application\.name'



Step 2: Use the sink number in following command. This will record audio in the out.rec file.

$pw-record --latency=20ms --volume=1.0 --format=f32 \
          --channel-map stereo --latency=20ms \
          --rate 44100 \
          --target="80" "out.rec"
 
Step 3: Convert audio to mp3 increase volume!


$ffmpeg -y -i out.rec -acodec mp3 -af volume=1.5 -b:a 320k  "OUTPUT_FILE.mp3"

Thursday, 29 February 2024

Configuring Raspberry Pi Infra Red receiver

WALT: Configure Infra Red Receiver for Raspberry Pi 2 (not USB IR receiver).

Hardware specs:

Infra Red Receiver and Remote

  • 3 pin Infra red sensor  -  VCC, GND and Signal.
  • Batterry controlled Remote control emits Infra red light. The remote emits Pulse width modulated IR.

Raspberry Pi

  • RPi 2 model B.
  • All GPIO pins for RPi are capable of Pulse width modulated digital input! Few GPIOs pins are capable of hardware PCM.
  • IR sensor connected to 5v, Gnd and a GPIO.

Software:

  • The Kernel does the Software demodulation of the Infra red signal received from IR sensor.
    • For Raspbian version bullseye, the "gpio-ir" kernal overlay does this. For remote controls that follow standard protocols like NECs, there is no need for lirc.
    • Change the /boot/config.txt file to activate the kernel overlay and reboot.
    • Once rebooted /dev/lirc0 should show up automatically.
  • Use the ir-keytable program to map the demoduled hex keys to the standard keys.
    • For e.g. 
    • $sudo ir-keytable -k 0x45=KEY_1,0x16=KEY_KPASTERISK,0x18=KEY_UP

Sunday, 3 January 2021

Add MP3 file ID3 tags

$ffmpeg -i <input_file> -metadata title="<>" -metadata date="2020" -metadata album_artist="<>" -metadata artist="<>" -metadata track="<>" -metadata language="<>" -metadata genre="<>" -metadata album="<>" <target_file>


Saturday, 2 January 2021

ImageMagick Crop, Chop PNG and make a PDF

 


Scripts to chop, resize PNG file using ImageMagick (Convert)

001_multi_convert_text.sh

#Submit first
./002_cropImage.sh "" &

#Submit rest 
for x in {1..40}
do
y=$((x+1))
./002_cropImage.sh $x &
done
exit 0


002_cropImage.sh

#!/bin/bash
to_replace="."
temp="_edited."

for a_file in $(ls -tr | grep -E ^$1[0-9]\{1\}\.png)
do
echo "Now doing input file - "$a_file" Output will be " ${a_file//$to_replace/$temp}
# convert $a_file -crop 1920x1080+1920+95 ${a_file//$to_replace/$temp}
# convert $a_file -crop 1000x1080+460+0 ${a_file//$to_replace/$temp}
# convert $a_file -crop 1000x1000+2400+95 ${a_file//$to_replace/$temp}
convert $a_file -gravity West -chop 470x0 -gravity East -chop 470x0 -gravity North -chop 0x20 -gravity South -chop 0x40 -resize 80% ${a_file//$to_replace/$temp}
done
exit 0


Command to merge the PNGs to a PDF

convert -quality 100 $(find -type f -name '*edited.png' | sort -V) output.pdf

Monday, 21 October 2019

Marathi (Devnagri) Text to Speech

Marathi TTS methods.

Better of the ones tried so far is the Undocumented (but widely used) Google translate API.

The TTS methods tried so far.
1. Undocumented "Google translate API".
2. CMU_INDIC speech synthesis on the Festival Speech Synthesis System.
3. CDAC JunuBharutee festival-mr package on the Festival Speech Synthesis System.

Undocumented "Google translate API" 

A simple python wrapper to call Google TTS (gTTS) python library recurrsively to overcome the 100 character limit and save output in mp3 format. This results in incorrect pauses, phrasing but found to be acceptable.

CMU_INDIC speech synthesis

Install Festival and the package as per instructions as on the original locations.
$festival
festival>(voice_cmu_indic_mar_aup_cg)
festival>(tts "/home/marathi.txt" nil)

The above will use aplay to output marathi speech.

cp /tmp/audiofile_xxxx temp.raw
To convert the raw to wave
ffmpeg -f s16le -ar 16k -ac 1 -i temp.raw file.wav

Wednesday, 3 April 2019

Scale , Crop , Resize photos for OCI India

Current OCI photo requirements.

... the images must be in jpeg or jpg format, with max size 200kb.

The height and width of the Applicant Photo must be equal.
The minimum dimensions are 200 pixels (width) x 200 pixels (height).
The maximum dimensions are 900 pixels (width) x 900 pixels (height).

Use GIMP - free and brilliant tool on Ubuntu.

Step 1: Open the original photo. File --> Open

Step 2: Crop the Image. Tools --> Transform Tools --> Crop. Select the area of the photo such that height and width is same number of pixels i.e. aspect ration 1:1.

Step 3: Scale the Image. Tools --> Transform Tools --> Scale. Enter height and width as 900px. This will scale the selected photo to 900 by 900 px. 

Step 4: Change the canvas to the layer size. Image --> Fit canvas to Layers.

Step 5: Export the resultant image. File --> Export --> select jpeg , jpg. 

Step 6: Select "Show preview in image window" so that File size is visible. Adjust Quality so that the file size remains under 200Kb.

Monday, 24 December 2018

Share internet with Sky box (not Q) over ethernet from raspberry pi connected to internet via WLAN0.

Moved house. Have old sky box with no WiFi.
Raspberry pi USB WiFi cost couple of bucks just besides sky box able to access internet.

So aim is to share the internet with Sky box. So connected the Sky box to Pi with ethernet cable.

On Raspberry pi:

  • Edit /etc/dhcpcd.conf to add following. IP address for WLAN0 is not one of the following.


interface eth0
static ip_address=192.168.2.1
static routers=192.168.2.255
static domain_name_servers=8.8.8.8

  • Install dnsmasq. Edit /etc/dnsmasq.conf to add the following lines.

interface=eth0 # Use interface eth0 
listen-address=192.168.2.1 # listen on 
# Bind to the interface to make sure we aren't sending things
# elsewhere 
bind-interfaces 
server=8.8.8.8 # Forward DNS requests to Google DNS domain-needed # Don't forward short names # Never forward addresses in the non-routed address spaces. 
bogus-priv
# Assign IP addresses between 192.168.2.2 and 192.168.2.100 with a # 12 hour lease time 
dhcp-range=192.168.2.2,192.168.2.100,12h


  • Edit /etc/sysctl.conf to forward ipv4.
  • Restart. Make sure the WLAN0 interface has the ip address from the configured IP range.
  • Forward the ports.
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sudo iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT

  • Restart