I am currently working a project like this. Although I cannot provide you the actual code, I can provide you the blog post and reference that actually do this.
Both post provided code examples and the first one goes more into the theory behind this. I hope this helps.