Tuesday, 28 July 2015

Creating a Simple Bot using the Telegram Bot API

So Telegram recently released an API for creating bots on Telegram! It's quite cool. Already, people have released nice Python libraries for it. For this bot I'm using one of them.

I decided to create a simple Telegram bot that I can use to control the music on my laptop. It's a testament to the power and simplicity of Python and the convenience of the linux terminal that it only took me an hour to develop this. Head over to my repo at gihub if you want to look at the code!

Here's a video of it working!


Movie Review - Whiplash

Note: This post may contain spoilers.


I used to watch sci-fi and animated films exclusively but now every once in a while I watch a random movie just for the fun of it. Yesterday that random movie turned out to be Whiplash - a movie about an aspiring drummer and his well intentioned but abusive mentor.

I loved the movie but I disagree with the opinions of Terence Fletcher. There is a scene in the movie where he is asked if there is a line. If there is a limit which if he crosses he might actually discourage his student from becoming the next great musician that the world loves. And he replies that there is no such limit because the next great won't be discouraged. While that's a cute sentiment, I think he's wrong. The world isn't divided into 'The Greats' and talentless people. There are plenty of people who fall in between the spectrum. And I think that by not caring about those who are not destined to be 'Great' and even actively doing things that could damage them mentally he is doing more harm than good. Additionally, I think that there are a lot of people who respond much better to constructive criticism and positive reinforcement than to abuse hurled at them. For every person with a story about an abusive mentor who made them who they are, I think there are a few dozen people with stories about how their incredibly supportive and positive mentor inspired them to be their best.

So while the story was inspiring, I really hope that people don't use Terence as an inspiration. 

Saturday, 18 July 2015

Maker Faire Singapore

The day before yesterday I found out that there was a Maker Faire going on in Singapore this weekend! I immediately scrapped all my other plans for the weekend to get there. It was definitely worth it. I owe a lot to the maker movement. It's what got me interested in engineering and I think it's a big part of the reason I am the person I am today!

The highlight of the Maker Faire was definitely the whole hall dedicated to Intel Edison projects! There were so many cool things in that hall! I have to admit that I only had a vague idea of what the Intel Edison did before saw all those demos. It's a pretty capable SoC. My favorite demo were these dancing hexapods. They were really cool to watch. The second best demo was the robot with omni directional wheels.

The Dancing Hexapods



There was also quite an impressive display of 3D printing at the Faire. There were so many exhibits related to them! Apart from the conventional designs using steppers to move the extruder in the X-Y plane I also saw a 3D printer based on a delta robot.

Saw this 3D printer that could print huge parts

The delta robot 3D printer

Why Self-Driving Cars are the Future of Personal Transport

So Google's self driving cars are getting really good at self driving. A lot of people I know are skeptical about self driving cars. Some say that they will never use them because they just love to drive. I think that once self driving cars are actually on the road, they won't have a choice.

From everything the the testing of the self driving cars have shown so far, they seem to be much safer than human drivers. They don't get tired and they never break the rules. Human drivers on the other hand, cause millions of deaths every year due to carelessness and driving while sleepy, drunk or under the influence of drugs. Even if self driving cars only cut down the number of car accidents by half we have a moral obligation to switch over. By making the choice to continue driving manually we are making the choice for millions of deaths to continue happening every year.

I think that sometime in the distant future people will talk with horror about the time that people were allowed to drive their own cars. Just like we now talk with horror about the horrifying state of medical practices before we knew about germs and how exactly the human body worked.
 

Friday, 3 July 2015

Terminator Genisys – Review

I watched the movie a few days ago. And I thought I’d write down some thoughts I had about the movie.
 
First of all, I have to admit that although I roughly know what happens in the earlier movies I have only watched one of the previous three movies.So this is the first Terminator film the I’ve watched fully.

For me, the movie was just OK. Nothing spectacular. Visual effects were nice and that was probably the best part of the movie.

Apart from the fact that the movie uses a completely overused plot of using time travel to reset what happened in the earlier movies, my main complaint about the film is the portrayal of the new enhanced symbiote John Connor as evil. By merging with the machines, John Connor has finally solved two of humanity’s greatest problems: aging and disease! Why does the movie portray that as bad?
In fact, one of the most most interesting thing researchers in medicine are working on right now is using nanobots for targeted drug delivery. Imagine having an army of nanobots inside you making sure you don’t age and never get any disease.

If everyone were to merge with the machines like John Connor did there would actually be peace again and human civilization would have taken the next logical step of using their now immortal bodies to explore the vastness of interstellar space!

For once the AI in the movie has a goal to work together with humans and they just had to portray that as evil. I’d love to see a Terminator film where the humans and the AI (it’s supposed to be super intelligent!) finally realize that the best thing to do is cooperate.

Monday, 22 June 2015

Another Weekend in Singapore

Now I’m working for a lab I guess I have a good idea of what working a 9 to 5 job will be like. I barely have time to do anything on weekdays. Free time has become a very precious resource. So weekends are the only time I get to actually do stuff. And most of the time, after a busy week all I feel like doing on the weekend is relax.

I’ve started going to the movies almost every week now. I didn’t have an opportunity to do that in Trichy. The theaters there are horrible. They tend not to show the kind of movies that I want to watch and when they do they either run it at a really inconvenient time or they dub it in Tamil. This place is heaven compared to Trichy. There are so many awesome places to see and visit! And so many good theaters!

Last Saturday, I decided to go visit the library. I felt like sitting in a quiet place and relaxing by reading something. I hadn’t done that in a really long time. I browsed around till I found a book that caught my eye. It was “Contact” by Carl Sagan. And I just sat down there and read for the next 4 hours. I really missed doing that. I’d do that a lot when I was a little kid. But after starting college I didn’t have much time to do that.

I went back to the library again on Sunday. This time I thought I’d do some reading on machine learning. There were these tables with power sockets on them set aside for people who wanted to do some work in the silence of the library. It was nice to sit there and work. The girl sitting beside me was also studying machine learning apparently. She had this book called “Supervised learning With Complex Valued Neural Networks” on her desk.
I think I’ll visit the library at least once a week from now on. It was nice to take a break from the general noise of the city.


I took a picture of the library building! It looks pretty cool!
image

Saturday, 20 June 2015

Using IFTTT for blog syncing.

So since I decided to keep both my blogs running in parallel, I’ve only posted two blogposts and I’m already starting to find it annoying to update both blogs every time I get a new idea for a post. So I decided to try out this thing that I signed up for a long time ago, but never really used till now. IFTTT (IF This Then That). It’s a web service that allows you to automate your social media accounts by having certain actions triggered automatically when you do something. For example, you can set it up so that whenever you like a video on youtube, it’s automatically tweeted or shared on Facebook or posted on your blog. It’s actually quite brilliant!
Now I signed up for this service when it was just starting out because I thought it was a really cool idea. But at that time I didn’t really have much going on in the web. So even though I had an account, I never really used a single recipe till now. Now I’ve finally created one so that whenever there’s a new post in my wordpress blog on my website, the same thing is automatically posted to my blogger blog as well.

Friday, 19 June 2015

Analysing sound in Python

I'm trying to build a simple word recognition system in python. As a first step, I needed to find a way to get audio sample data from my microphone and store it in a numpy array in Python. After a lot of searching and experimenting I finally found a library that works well for this task: pyalsaaudio.

This small piece of code records roughly two seconds of audio from the default microphone and plots the spectrogram. This was actually a bit tricky to figure out so I thought I'd share the code for anyone out there who might be trying to do this.
#!/usr/bin/python

import struct
import alsaaudio as aa
import numpy as np
import time
import matplotlib.pyplot as plt
from pylab import *

SAMPLERATE = 8000
PERIODSIZE = 160
CHANNELS   = 1
CARD = 'default'


inp = aa.PCM(aa.PCM_CAPTURE, aa.PCM_NONBLOCK, CARD)
inp.setchannels(1)
inp.setrate(SAMPLERATE)
inp.setformat(aa.PCM_FORMAT_S16_LE)
inp.setperiodsize(PERIODSIZE)

sound = np.array([0])

if __name__=='__main__':
    ctr = 20000
    while ctr > 0:
        ctr -= 1
        l,data = inp.read()
        if l:
            samples = struct.unpack('h'*l, data);
            sound = np.append(sound, np.array(samples))
        time.sleep(0.0001)

    print(sound.size)

    
    #plt.plot(sound)
    #plt.ylabel('amplitude')
    #plt.xlabel('time')
    #show()
    
    Pxx, freqs, bins, im = specgram(sound, NFFT=1024, Fs=8000, noverlap=900, cmap=cm.gist_heat)
    show()