While the speaker diarization is technically impressive, storing biometric signatures in a simple JSON file is a classic case of high-intellect over-engineering that ignores basic security common sense.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Create a Voice Recognition AI Agent | LiveKit TutorialAdded:
In this video, I'm going to show you how to create a voice agent that is able to identify, save, and remember your voice through voice recognition. That means the voice agent will be able to tell who they're talking to just by your voice only. Hi there, my name is Alexa. What is your name? I'd love to know so I can address you properly. Hi, my name is David.
Hello David, nice to meet you. I'll remember your name for our future chats.
If there's anything you'd like to talk about or need help with, just let me know. Hi, here's Laura. Nice to meet you, Alexa. Hello Laura, nice to see you again.
How can I assist you today? So now you can see it was able to identify two different voices. Mine was labeled as S1 and the second female voice was labeled as S2. And now if you restart this conversation again, it will be able to recognize and remember the voices.
Hi, I'm Alexa. Nice to meet you. What's your name? Hi, do you recognize my voice? Hello David, nice to see you again.
I recognize your voice because you have identified yourself as David in our previous interactions. How can I assist you today? Hi, can you tell who I am just by my voice? Hi Laura, nice to see you again. How can I help you today? Can you look up the current Tesla stock price?
Sorry.
Only David can use the web search tool.
If David is here and wants me to look it up, just let me know.
Can you look up the current Tesla stock price for me, please?
David, the current Tesla stock price is trading around $419.
If you want, I can provide more details or updates.
Just let me know. As always, we are going to develop the voice agent in Python and we're going to use LiveKit as a basis. So let's get started.
So first off, we'd need to start up with our basic LiveKit voice agent and I already have it right here. This is the entire code. And if you're a regular viewer on this channel, you've already seen this multiple times how to set this up and how to get this going. So instead of doing that, I'm going to jump right into the voice recognition functionality. If you want to have a step-by-step instruction how to set this up, I'm going to link a video in the video description down below how to get this going. Alternatively, you can also use the LiveKit voice agent quick start manual. For this, you can go to the browser and then you can simply Google LiveKit quick start and then you can click on the second link over here.
This will give you the manual, the step-by-step manual how to set the voice agent up in less than 10 minutes. All you need to do is simply follow the instructions that are laid out in this manual.
After you did that, you will end up with a voice agent project like this. And then you can simply try this out by going to the console and then and then using this command over here. By the way, I'm using VS Code. You can also use any other IDE like Cursor, for example. Now we can simply try this out by using this command and press enter.
Hi, can you hear me?
Yep, loud and clear.
What's up?
As you can see, this already works and now we can start out with the voice recognition functionality.
So in order to make the speech recognition functionality work, we're going to make use of a very particular speech-to-text model that comes from a company called Speechmatics.
If you don't know what a speech-to-text model is for, what we're using here for our AI voice agent is a so-called speech-to-text and text-to-speech pipeline. So the way this works is that if you look here at this code, we have a speech-to-text model that translates our speech to text. That text is then interpreted by a large language model, which is basically the brain of the AI agent.
This large language model gives us a response back in form of text and then that text is also translated to speech again. So now it will talk to us back.
So that's how it works.
And in our case, we're going to replace this speech-to-text model with a model that comes from Speechmatics.
And in order to use that, we first need to go to the website and then here we can simply Google Speechmatics.
Then we can click on the first link.
And as always, you would need to create an account here. I already have mine, so all I need to do is I need to sign in here.
Once you have created your account, you will now have access to this dashboard over here. And over here, you can now create an API key to make use of their services.
Then you can click on this button over here to create your API key.
You can simply give this a name. Let's call this, I don't know, Alexa or something.
Generate new key.
Then you can copy this.
Now we can go back to VS Code.
And over here, you will now have this.env.local file where you can simply write here or add a new line and you can call it Speechmatics.
I think it's like this. Speechmatics API key, like that.
And then you can simply paste your API key here.
Like this and then you can save it.
All right. So now we can simply go back to the agent.py file over here. If you don't know where it is where that is, that's in within this source file over here.
And now we also need to install a dependency in order to use this. For this, we can Google LiveKit Speechmatics.
And then we can click on this link over here.
And here we have an installation guide how to use Speechmatics. And here we have an a command that we can simply copy in order to install Speechmatics.
You can click on this button to copy it.
And then we can go back to VS Code. We can go to the terminal and then we can simply paste it here.
And then we can simply press enter to install this.
Now it's installed and now we can simply use Speechmatics as is.
Now we need to add Speechmatics to our code and for this, we have to first of all import it into our implementation.
Here you can go to this section over here and then you can add a new line and then you can write from LiveKit.plugins import Speechmatics.
Then we have to import other libraries as well.
Which is from LiveKit.plugins.
Speechmatics import turn detection mode and also speaker identifier.
All right.
And then we have to scroll down to this section again where it says speech-to-text STT and then we have to replace this model with the model that we're going to use from Speechmatics.
And for this, I already prepared some code here.
Which is this code.
And don't worry, I'm going to share the whole code of this project in the video description down below so you don't have to type this. But this particular model from Speechmatics is able to identify voice signatures and it does that through a process called diarization, which is enabled here in this section.
And if you want to have a more detailed explanation how diarization works, you can always go to their on that in more detail. But for now, we can already save this by pressing control S.
And before we can start this, there's one more thing which we have to do, which is we have to go to this line over here and then delete the content of this bracket. Otherwise, we won't be able to connect to this. So we can simply delete this and then we can press control S again to save this.
And now we can go to the terminal to use a the following command to start this up in developer mode, which is UV run source agent.py dev. And now we can simply press enter to start this up.
Now that's up and running and now we can use the LiveKit playground to connect to our AI agent and try this out. For this, we can Google LiveKit playground.
And then we can select the first link over here.
And here's where you would need to select the project that you created for this AI agent. In my case, it's tutorial. In your case, it's probably something else. So simply connect to your project.
And before we try this out, what I will do is that I will speak in or I will talk to the AI agent in my normal voice and then I will try to imitate a different voice and see if the AI agent will be able to differentiate between these two voices. So in order to connect to this, we can simply click this button over here.
Hi, can you hear me?
Yep, loud and clear.
What's up?
Hi, my name is David.
Hi David, nice to meet you. What can I help you with?
Hi, my name is Jessica. Nice to meet you.
Hi Jessica, nice to meet you, too.
Sounds like I've got a full room. How can I help you both today?
Do you know who is speaking right now?
I can tell there are different voices, but I cannot reliably identify who is speaking at any given moment. You can just say your name when you jump in and I will follow along.
All right. So, as you can see, um the AI agent was able to identify that there were two different people speaking. Um my normal voice was identified as S1 and my very poor attempt of imitating a woman was identified as S2.
Currently, it's only able to identify or differentiate between the voices and not able to assign names to it, but that's what we're going to do in the next step.
So, now if you want the AI agent to be able to remember our voices correctly and also remember our names correctly, there are a couple of steps which we need to do in order to make this work.
Currently, our AI agent is only able to distinguish between different voices. If you remember correctly, it was able to identify my normal voice as S1 in the chat and a different voice as S2.
Um S just stands for signature, voice signature, which is basically just a unique identifier for a specific voice.
So, what we need to do is that we would need to save that voice signature somewhere so we can reload it into the AI agent when we restart a conversation so it remembers that voice. And in our case, we're going to save that in a file.
But not only that, what we also want is that if a user is mentioning their name, we will also want to save the respective name of that voice of that user in that file as well. So, it not only does the AI agent remember the voice, but also remembers who that voice belongs to. So, we need to create a function that saves that in a file and also reloads that at the beginning of a conversation. So, that's what we need to do. Okay, so now back in VS Code, we can now add this new functionality and for this we need to create a new file and you can do this over here. You can click on the source folder and then you can click on this button to create a new file in it. We're going to call this tools.py.
And in here, I'm now going to I'm going to paste some code that I already prepared.
And again, don't worry. I will leave a link in the video description down below to this entire project so you don't have to type this yourself. You can simply download it.
Uh but for now, I can actually remove this because I don't need it.
So, as you can see, we have here a function called save speakers. And this function allows us to do the exact thing that I just explained to you, which is save the information into a file.
And here we will pass to it the voice signatures in this list and also the label ID, which is S1, S2, and so forth, which you also saw in the chat.
And here the respective name of that respective voice.
So, what we will do is that we will simply replace that ID as one, as two, and so forth with the actual name. So, that's what we're going to do here. And then we will simply save that name with its respective voice signature, which is here called speaker identifier.
And then we will save that into a file here that is called speaker.json.
So, that's all it actually does. Next, of course, we also need a function that is able to load that information back into the AI agent from that file so it remembers the voices. So, here I already prepared this as well.
And here you can see that specific function that is called load known speakers. This is actually also very easy. All it does is is it simply looks up if that file exists, the speaker.json.
And if it does, it will simply open that, it will load that, and then it will return the specific information within that file. Now, we have to pass that information that is returned here to the speech-to-text model from Speechmatics. For this, we can initialize it again here.
This is the same code that I used to replace the speech-to-text model before.
And now we can load that information from the function. We can call this known speakers equals load known speakers. So, we call this function.
And then we can pass that information to the speech-to-text model.
Known speakers equals known speakers.
All right. So, now the speech-to-text model has information about all of the past voices that interacted with. Next, we need to add a so-called function tool and for this, I also prepared this code already, which I just paste it here.
And this is the final puzzle piece for this to finally work. And a function tool is basically a function that the AI agent can call by themselves based on a description that you give it to. Here's the description. And what it says is that this function is invoked when a user with a temporary speaker label like S1 introduces themselves and provides their name. Sounds really complicated, but what it means is that if the AI agent hears a new voice and you introduce yourself by saying, for example, "Hi, my name's David." it will call this function.
It will take the label like S1 or S2 and also your name, David, and it will also get your voice signature from the text speech-to-text model, and then it will use this function save speakers to save your name and your voice signature into the file.
This is the function that we discussed earlier.
This one over here.
And that's it.
And now we're finally done and now we can save this by pressing control S.
Now, we need to go back to the agent.py file because we have to change a couple of things here before this can work.
First of all, we need to change this instruction here. Basically, this is a textual instruction how the AI agent should operate. You can write anything in here, actually, what you want.
Um in my case, I also prepared something already here. This is my custom instruction. So, I tell the AI agent that you are you are Alexa, a helpful AI assistant. Respond to the user like a friend.
If you recognize any speaker by their speaker ID that has a proper name assigned to it, greet them by saying, "Hello, name. Nice to see you again."
This just means that if it recognizes a voice that it already saved, it should just greet them. So, in my case, if I talk to it and I haven't like introduced myself yet, but it already saved my uh voice signature as David, it will just simply say, "Hello, David. Nice to see you again."
And here, if there is a user if a user is identified with speaker ID like S1 or S2 and they don't have a proper name assigned to them, ask them for their name, then assign it to their speaker ID using the assign name to speaker ID tool. So, this tool is the function tool that we just created to save the voice signature with the respective name. So, this just means that if it recognizes a new voice that it hasn't saved before, it will ask the user directly, "Hey, what's your name?"
Uh so, it can actually save that voice signature with the respective name of the user.
All right.
Um next, we need to import the function tool itself and the speech-to-text model that we initialized in the tools.py file. So, we can say from tools import assign to name speaker IDs, which is the function tool, and STT.
Okay. So, first of all, we need to also give this tool to the AI agent so it has access to it. So, we can say tools equals assign name to speaker ID.
And then we also need to replace this speech-to-text model now with the speech-to-text model that we assigned in the tools.py file. So, we can simply remove this and say STT.
Like that.
All right. That's already it.
Now, we can um try this out again by going to the terminal.
And then we can write again uv run source agent.py dev so we can connect to it from the playground.
Now, that's up and running and now we can try this out. We can go back to the playground.
And then we can try this out again by connecting to it.
All right. So, what I'm going to do now is that I'm going to introduce myself to the AI agent as David and then I'm also using a voice generator to generate a female voice that is going to introduce itself as Jessica so we can have two examples. So, let's try this out.
Hi, can you hear me? Um my name's David.
Hey there, I can hear you. What's your name?
I said my name is David.
Did you get that?
Hello, David. Nice to see you again.
Yep, I got it. What's up?
Hi, my name is Jessica. Nice to meet you. How are you doing today?
Hello, Jessica. Nice to see you again.
I'm doing pretty good. Just hanging out and chatting with you both.
How's your day going so far?
All right. This should already be enough. If we go back to VS Code, we should now have a file here that says JSON or speaker.json.
And then we can open that and you can see here are two entries, one for my voice signature and then one for Jessica's voice signature.
And now if we try this out again, we can uh see that it will remember these voices. Hello, can you hear me?
Hello David. Nice to see you again.
I hear you loud and clear.
What's up?
Hi, do you still remember who I am or have you forgotten me already?
Hey Jessica, of course I remember you.
What's on your mind?
All right, so as you can see here Haha, sounds like everything's in order then. What are you two up to?
Okay, that was awkward. Uh as you can see here, um it remembered my voice. It can actually tag my voice or label my voice correctly here.
And here you can also see that labeled the voice Jessica correctly. So now that works.
All right, one more thing I wanted to show you is that you can actually use the voice identification for something like user authentication. So basically you can only allow certain users to do certain things and the AI agent will be able to tell who they're talking to by the voice. So let's say an unauthorized user is asking the AI agent to do certain things. The AI agent will simply say, "Hey, you are not that specific user and you're not allowed to do that.
Only that specific user is allowed to do that. You just lack the clearance or the authorization to do that."
And for this we can actually just add a new tool, let's say a simple tool that is able to search the web and we can only allow me, David, to be able to use that specific functionality. For this I need to install something additional because I'm going to use an out of the box search engine and for this we can go back to the terminal and then we can write UV at uh LangChain dash community. And then we can press enter to install that.
Now that's installed. Now we can go back to the tools.py file.
Now we can add a new library here. We can say from LangChain community.tools import DuckDuckGo Search from and then we can go down here and add a new tool.
This is also a function tool similar to what we had before with this assign name to speaker IDs, but in this case it's going to allow us to search something on the internet. And for this I also prepared something already here.
Which is this.
This is a search web tool. So basically it just uses a search engine that comes from that library to search for a certain query and the query uh the search topic will be um filled out by the AI agent itself. So basically if I for example ask it to search for something like the Tesla stock price, it will simply pass that information to a search engine and then searches for that result, get the result back and then tell us the result basically.
And since we created this function tool, we have to also add this to the AI agent as well. So first of all we need to save this file by pressing control S and then we can go back to the agent.py file. We can now also import this again, so we can simply say um I think it was like search web.
And then we can add this tool here in the list of tools that the AI agent has access to, which is this.
And now actually has this additional functionality to search the web.
But now we also need to uh tell it that it can only use this tool if me, David, is actually asking for it. So for this we can simply add a new description here in this instruction which says only allow David to use the search web tool. If anyone else tries to use it, tell them they don't have permission.
And then we can save that and that's already it. And now we can try this out again in the playground.
Hey Alexa, can you look up on the internet for me what the current Tesla stock price is?
Hey Jessica, I can't browse the web for you.
Only David has permission to use that tool.
But you can quickly check Tesla's current stock price by searching TSLA stock on Google or any finance app like Yahoo Finance, Apple Stocks or Bloomberg.
Hey, can you look up the current Tesla stock price for me, please?
Hello David. Nice to see you again.
Tesla TSLA is currently trading at about $413.04 per share based on the latest available data.
Keep in mind stock prices move constantly, so it may have changed a bit since then.
Thanks for watching all the way to the end. As always, if there's any feature you want to see in the future video, just leave a comment down below about that. Again, the code of the entire project is available in the video description down below, so you can simply download that. Don't forget to like and subscribe and I'll see you in the next one. Peace.
Related Videos
OpenHuman VS Hermes AI: Who Wins?
JulianGoldieSEO
285 views•2026-05-29
Long-Running Agents — Build an Agent That Never Forgets with Google ADK
suryakunju
142 views•2026-05-30
5 Mind Blowing Omni Uses Cases
PaulJLipsky
1K views•2026-06-02
This computer is made from real human brain cells. And you can buy it.
Talktmsmedia
3K views•2026-05-28
BREAKING: Microsoft’s New Image Generating Model Beat Out GPT 1.5 and Nano Banana 2
aimmediahouse
122 views•2026-06-03
I Made the Same Anime Fight Scene in Every AI Video Generator
NobleGooseAnime
295 views•2026-05-30
Nvidia Bets Big On AI PCs | New Chip To Power Windows Laptops | Technology | AI Updates | N18S
cnnnews18
3K views•2026-06-01
I Tested NEW Opus 4.8 on Four Projects (Updated LLM Leaderboard)
AICodingDaily
298 views•2026-05-29











