/ai-transcription

Transcribe audio with Whisper and speaker diarization

Primary LanguagePython

AI Transcription

This python script will:

  1. Scan a folder
  2. Convert audio file to wav
  3. Run speaker diarization and output rttm file
  4. Transcribe to a markdown file

Transcribe audio with Whisper and speaker diarization.

python3 main.py -i <path-to-input-dir> -o <path-to-output-dir> -w <path>/whisper.cpp/main -m '<path>/whisper.cpp/models/<chose-model>.bin' -s 2

Files in the input directory can be .mp3 and .m4a or .wav.

It runs pretty slowly, but the goal is that your recordings can be saved to a folder that is constantly watched by this script and then the transcription would eventually show up in your Obsidian vault or whatever app is used to manage transcriptions.

Requirements

  • Whisper.cpp setup with models downloaded already
  • Python
  • A huggingface token (replace it in main.py)
  • ffmpeg installed

Example

Input: destin-example.m4a (Source)

Command: python3 main.py -i 'recordings/in' -o recordings/out -w whisper.cpp/main -m whisper.cpp/models/ggml-large-v2.bin -s 2

Output:


00:00:00 - 00:03:11 [[Destin]]: Hey, it's me Destin. Welcome back to Smarter Every Day. I just interviewed the President of the United States of America, which is really strange because I'm not a journalist, I'm not a politician, I'm a rocket engineer, which means I'm going to come at this thing from a completely different angle than most people. The process of interviewing the President is strange because you learn things about him and the White House, of course, but you learn things about yourself. Four parts to this video, the mechanics of how this happened, what my goals for the interview were, the interview itself, and what I learned. My understanding is there was a long list of people being considered, and at some point I was interviewed as a potential candidate. I'm not a registered Republican or Democrat, but they asked me point blank who I voted for, and I didn't tell them, but the way I answered the question made it pretty clear to me I was not going to be selected. But I was. It was a secret for three weeks, and then I went out to LA to shoot a promo for the interview. It was there that I met Adande and Ingrid. They were super cool and really down to earth. When I got home, I asked the internet what they thought I should ask the President, and I got all kinds of answers. I mean, good ones, bad ones, it was amazing. But think about it. I don't agree with the President on every single issue, so I have a huge opportunity here. I could sit down with the most powerful man in the world and tell him how I think he should run the country, or I could accept the fact that he might see things differently than I do and try to have a meaningful, intelligent, respectful conversation. My goal was not just to have this intelligent, respectful conversation with somebody I might disagree with on other topics, but to demonstrate that it could actually be fun. To do this, I went to Washington to meet the President. The day before the interview, we went to a studio in Maryland, and we practiced with a guy named Frederick. He was a stand-in hired by Google, and he was a really cool guy. The next day, we went to the White House, and we got to meet the President's dogs, which were really, really soft, by the way. We did some dry runs to make sure we knew how to roll our sets around, and then each of us kind of went off and reviewed our questions one last time to make sure we knew what we were going to say. We then waited for the President, and he walked in, and we started the interview. The President had already been briefed on who the three of us were, and the fact that Swoozie was going to give him a lightning round, and I was going to watch a video with him, and that Ingrid was going to ask him about what's in his pockets. A lot of people want to know, "Did I share my questions with the White House?" These are actual cards before the interview, and the answer is no. This is how I know this. I was looking into his eyes during the interview, and it was clear through nonverbal communication that these things were hitting him cold. That impressed me. When I figured that out, I was like, "Holy cow. A common citizen going to the White House, talking to the most powerful man in the world on a live, internet interview. That is an incredible amount of transparency, and I don't care what you say about the man's politics." That impressed me, and I appreciated that. For many reasons, I wasn't nervous. I was actually really excited about this. I decided to ask the first question on how he gets smarter on topics he might not be the expert on. It was an interesting answer because it's clear that he's changed his methods over the course of his presidency. As he was answering this question, it was pretty clear to me that he was in interview mode. His body language was a little rigid. Now, keep in mind that at this point, the president still doesn't know what kind of interviewer I'm going to be. For all he knows, I could be hostile. What happened next was a moment I will never forget. I knew before he did that we were both on the same wavelength, and I really wanted to let him know that. After all, I had listened to him already for 10 hours via audiobook. If you watch the president's face, you can see the exact moment that we connected.

00:03:12 - 00:03:17 [[Obama]]: And that I think is pretty consistent with how scientists approach problems in general.

00:03:17 - 00:03:59 [[Destin]]: Now, I actually knew that about you because I've listened to your audiobooks. And in Dreams of My Father, it ended with the 2004 Democratic National Convention speech. Did you see it? Let's back it up and watch his body language. He's a little guarded, and then the connection. Isn't that cool? It's the exact moment that this quit being an interview and became a fun, intelligent conversation between two individuals who want the best for each other. It was a really cool moment, and I won't forget it. My second question was about polarization. It's been clear to me that the country is more polarized now than it's been in a really long time. And in fact, there's data to back this up. Whatever your views are, it's become really popular to yell at the other side and blame them for all the country's problems. The president went into why he thinks this is happening.

00:04:00 - 00:04:23 [[Obama]]: And the problem is that when we get to our politics, for a whole host of reasons, a lot of it having to do with the fact that our media is now splintered. And so some people, they're just watching Fox News, some people are just reading the New York Times. So they're not, they don't even start with a common baseline of facts. They almost occupy two different realities in terms of how they see the world.

00:04:23 - 00:05:29 [[Destin]]: In engineering control theory, there's something called a feedback loop. There's a positive feedback and a negative feedback. If you remove negative feedback from any system, it almost always goes divergent and chaotic. This is not political science. This is math. When people on the left or the right only listen to the media that agrees with their way of thinking, that's a dangerous situation. If there's no negative feedback pulling you toward the center, you're going to drift out closer to the extremes. I really appreciated what the president said here because it's the responsibility of everybody on both sides of the political debate to listen to both sides of the argument. If not, you're going to be in an echo chamber and you're only going to listen to those voices that amplify what you want to hear and pretty soon there's nothing but yelling. My third question was about space, which is when I solicited the presidential fist bump then forgot to blow it up like a gentleman scholar. Anyway, you can tell by my face I was really excited about this question and I'd love for you to go listen to the president's answer. I wanted to end on a fun note, so I asked him this really cool question from Reddit. If there was an element named after you, Obamium. You've never been asked this I hope. I have never been asked this. Yes, right? So the question is, this is fantastic.

00:05:27 - 00:05:38 [[Obama]]: So the question is, this is a first, so what would you want the physical properties... What would be the elements? What would be the characteristics of Obama?

00:05:34 - 00:07:51 [[Destin]]: -Obama is the element. -What would be the characteristics of Obama? -That's right, that's right. -Now that's interesting. I'm not gonna play his answers now because I encourage you to go watch the full interview in its entirety on the White House's YouTube channel. Okay, time to talk about what I learned. The exercise of thinking through what you would ask the most powerful man in the world is very different when you're sitting at home on the couch or talking to your buddies around the water cooler than if you're actually planning on going and sitting down and looking him in the eye and asking him the question. I found myself wanting to be more informed, more cordial, I wanted to be more forgiving. Why is that? Why do we have a tendency to want to be disrespectful? There's two things I learned through the presidential interview process about how to communicate with people you might have a difference with. Number one, if I'm typing with somebody or I'm chatting on the phone, I'm gonna pretend that I'm sitting directly across from that person looking them in the eye because I want to be respectful and gracious. And number two, if I can just listen, it's huge. Think about it, if I listen not just to formulate my next response so I sound smart to them, but if I truly listen to connect with them at the heart level, my credibility and influence with that person goes through the roof, even if it's the most powerful person in the world. Think about that. Be respectful and listen. It's that simple, but it's really, really hard. Hey, thanks. This went from rockets in the backyard to interviewing the president, which is kind of crazy. Anyway, if this is your first episode of Smarter Every Day that you've ever watched and somehow you feel like this has earned your subscription, feel free to do that, but only if it earns it. Last thing, I want to thank the sponsor who's been with me from the low points all the way to now, which I would say is a high point, and that's audible.com. Clearly that's how I prepared for this interview, and I shot something while I was in the White House to tell you what I learned. Okay, I hope you enjoyed me in the White House. I know it was a blast. If you're interested in listening to President Barack Obama's books, the first one is Dreams of My Father. You can get that for free at audible.com/smarter-as-dreamsofmyfather. Totally recommend it. He's a really good reader. It's fantastic. Anyway, another book is called The Audacity of Hope. Feel free to go check out both of his books. I think it's very important that you know the thoughts of the guy that's leading the country. Anyway, if you like, check those out, audible.com/smarter-audacityofhope-and-dreamsofmyfather. I'm Destin. Getting smarter every day. Have a good one.