How to install KVM with a working audio (on Ubuntu)

I used the instructions here [1] to install the KVM on my Ubuntu 12.04, and was even successful at creating and running another instance of Ubuntu 12.04 as a guest OS.

But I could not get any sound from the guest, and it was important considering I am going to test some audio-related setup in these VMs.

I had to scour the interwebs and try different things to get the audio in Guest OS working, so documenting them here, in the hopes that someone finds these helpful, and I can refer back to them if needed in future.

The things we are trying to fix are:
1) Make KVM run as a non-root user, specifically, as your login, so that it can share your ALSA audio.
2) Make KVM to not disable audio.
3) Replace the KVM binary with a script that sets up proper environment variable, so that KVM and use your alsa audio driver.

Instructions follow:
cd /usr/bin
sudo mv kvm kvm.bin
sudo touch kvm
sudo chmod +x kvm
Edit /usr/bin/kvm and paste this text in it:
#!/bin/sh
QEMU_AUDIO_DRV=alsa /usr/bin/kvm.bin $@
Edit /etc/libvirt/qemu.conf and look for the following lines (remember all these lines are in different sections of this file) :
# vnc_allow_host_audio = 0
# user = "root"
# group = "root"
and replace root with your local user name, for example:
vnc_allow_host_audio = 1
user = "gurjeet"
group = "gurjeet"
Now restart the KVM service
sudo service libvirt-bin restart

Now launch your guest OS and enjoy its sound.

[1] https://help.ubuntu.com/community/KVM
[2] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=649442