From Insomnia to Innovation: Building SleepScape

This might happen with a lot of people – feeling insomniac at night, taking almost an hour to simply fall asleep. To ensure that I do sleep – I use apps like Calm, Headspace, and often YouTube to listen to something which might simply get my mind to calm down and not think about anything else. I know it’s hard but then again, the goal is to Sleep!

While the Apps do work, often, they don’t fall into the exact requirement that I have. Thus, the developer in me started brainstorming. I started thinking of building a mobile app using React Native for Android and iOS. It took me around a weekend to develop the interface. For APIs, I decided to make use of Cloudflare Workers with KV connected with S3-Compatible DigitalOcean Spaces. Obviously, I will be using Google’s Firebase for lots of things, especially, Auth.

At the moment, the important thing, that I have been trying to achieve is generating a human-like speech using various LLMs and TTS engines. I have tried ElevenLabs but it becomes too costly in the long run in generating these sleep stories. ChatGPT helped me figure out the comparisons between some of the engines and based on the requirements, I tried some of the other engines like Coqui TTS, Bark, and Tortoise TTS. Just to let you know, the configuration of my PC is i7-12700K, 64GB DDR5 RAM, 3TB SSD, and most importantly Nvidia RTX 3060ti (which can run these TTS engines easily).

I thought, I will first come up with an easy task of setting up and finetuning the code to get a better audio and then probably, if needed, I will rent a faster GPU like RTX 4090 from vast.ai or Azure Spot Virtual Machines to run these at a faster level.

Imagine…
You find yourself standing barefoot upon soft, sun-warmed sand…
Gazing out at an endless ocean, stretching toward the horizon…

A sample generated, which felt it’s good at least. Now need to finetune and keep testing to ensure that we are able to generate a set of voice configurations that could be used to generate the audio of the story.

Disable Screenshot in App

Many a times we have seen App which detect and won’t allow us to take screenshots. So as an App developer on Xamarin, it’s quiet intriguing to know how to achieve that. Turns out, it’s just a line of code that would allow us to achieve that.

this.Window.SetFlags(WindowManagerFlags.Secure, WindowManagerFlags.Secure);

Setting up the Flags for Window Manager does the job. Now just add this in a Blank Android App and test it out. You will see that it works just like that.

Happy Coding!

Speech To Text in Android using Xamarin

On this fine day of Teacher’s Day, my mentor from Aditi asked me if I know any samples on creating a simple app for Speech to Text recognition in Android. I searched on the net but did not find much result. So then I thought, why not I create a sample, push it in Git and send him the link.

So after an hour the sample was done and pushed to Git. Xamarin allows the use of Android APIs to be utilized in a very easy way.

In just few lines of code I was able to use the RecognizerIntent to launch an activity that will prompt the user for speech and send it through a speech recognizer. The results will be returned via activity results in the event handler OnActivityResult.

The sample can be downloaded and used as is from here.