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

Tuesday, 26 September 2017

Sharing Wireless internet connection on a PC running Ubuntu with the Raspberry pi connected to the PC via Ethernet cable

Sharing Wireless internet connection on a PC running Ubuntu with the Raspberry pi connected to the PC via Ethernet cable.


Laptop running Ubuntu.

Laptop connected to Internet via Wireless LAN.

Raspberry pi and Laptop connected using a ethernet cable. (Cable used to connect a PC to wired LAN. Not a special cable)

Raspberry pi running - RASPBIAN STRETCH LITE (Minimal image based on Debian Stretch)

Steps:

Raspberry pi

1. Enable ssh on raspberry pi. Google for the instructions depending on if you boot headless or have connected the pi with any input (keyboard) / output (TV / Monitor) device.
2. Confirm that DHCP client is running on Raspberry pi. By default the RASPBIAN STRETCH LITE has DHCP client running / listening on ethernet port.

Laptop

3. Install DHCP server.
$ sudo apt-get install isc-dhcp-server

4. Update the DHCP configuration with the IP range of your choice for your pi and laptop network.  Change the file mentioned below. Will need root access on Laptop.
$ cat /etc/dhcp/dhcpd.conf
subnet 17.1.10.0 netmask 255.255.255.224 { *****Network subnet *****
  range 17.1.10.3 17.1.10.30; *****Range of IP address that will be allocated by DHCP*****
  option domain-name-servers 208.67.222.222; *****Open DNS server*****
  option subnet-mask 255.255.255.224;
  option routers 17.1.10.1; *****IP address for the Laptop*****
  option broadcast-address 17.1.10.31;
  default-lease-time 600;
  max-lease-time 7200;
}

5. Set DHCP server to serve requests on the ethernet interface (device). Change the file mentioned below. Will need root access on Laptop.
$ cat /etc/default/isc-dhcp-server
INTERFACES="eth0"

UPDATE-
ON UBUNTU the if command does not work anymore. In order to assign a static IP address use the following--

Helpful names of the kernal interfaces like eth* have changed!!!

Following shows the entwork hardware and new names.
$sudo lshw -class network

$sudo ip addr add 17.1.10.1/24 dev enp0s25

If a static could not be assigned to laptop, the DHCP server deamon fails with error 

"No subnet declaration for <ethernet device> (no IPv4 addresses)."

The ethernet device is mentioned in the /etc/default/isc-dhcp-server. This file should have the appropriate name as per Ubuntu!

6. Set static IP.
$ cat /etc/network/interfaces
auto lo eth0
iface lo inet loopback
iface eth0 inet static 
address 17.1.10.1
netmask 255.255.255.0

UPDATE-
ON UBUNTU the if command does not work anymore. In order to assign a static IP address use the following--

Helpful names of the kernal interfaces like eth* have changed!!!

Following shows the entwork hardware and new names.
$sudo lshw -class network

$sudo ip addr add 17.1.10.1/24 dev enp0s25

If a static could not be assigned to laptop, the DHCP server deamon fails with error 

"No subnet declaration for <ethernet device> (no IPv4 addresses)."

The ethernet device is mentioned in the /etc/default/isc-dhcp-server. This file should have the appropriate name as per Ubuntu!

7. Set IP address forward.
$sudo sysctl net.ipv4.ip_forward=1

8. Set IP forwarding in IPTables.
$sudo /sbin/iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
$sudo /sbin/iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
$sudo /sbin/iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT

Set up wise thats it.

Commands to - 
Check IP address assigned to pi.
laptop$ nmap -sP 17.1.10.1/29

SSH to pi.
laptop$ ssh pi@<Ip address for the pi>

Check the route on pi or on laptop
laptop$ ip route

Check if domain resolution works fine.
pi$ ping www.google.com

Check the route to internet
pi$ traceroute www.google.com

Sunday, 9 July 2017

Ubuntu Wifi from command prompt.

List the available networks.

$nmcli device wifi list

Command to connect to a Wifi.

$nmcli device wifi connect password