Template code for Listening and Recording