Skip to content

Instantly share code, notes, and snippets.

@Jeremy-Gstein
Last active February 25, 2024 02:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jeremy-Gstein/d2f5cd18bce8f840e0bfb0a79c742b41 to your computer and use it in GitHub Desktop.
Save Jeremy-Gstein/d2f5cd18bce8f840e0bfb0a79c742b41 to your computer and use it in GitHub Desktop.
Messing around with OpenAI - API and Whisper

Messing around with OpenAI

Disclaimer: this was just for fun and to learn about openai

I started messing around with openai's API and wanted to share some CLI tools. The following was used to test these scripts. May create a small container or codespace for this in the future.

Enviroment Used:

Fedora Silverblue 37 (VM):

  • 4 x 2 Vcpus (8 cores total)

Packages Needed:

  • ffmpeg (audio/video decoding tool)
  • yt-dlp (download youtube vids fast)
  • python3, pip, and Whisper (see Openai whisper git repo)
    • these packages can be installed with your pkg manager.

Creating Enviroment to Work in.

$ mkdir dev; cd dev; mkdir Text Audio

Convert Audio to mp3 with yt-dlp and useing Whisper to convert mp3 to English text.

$ cat <<EOF > commands.sh
#!/bin/bash
#Get URL from user.
read -p 'Video link: ' YOUTUBE_VIDEO_URL 

#Convert given URL to a .mp3.
yt-dlp -x --audio-format mp3 $YOUTUBE_VIDEO_URL \
	-o ~/dev/Audio/audio.mp3 

# Transcribe .mp3 to English Text.
whisper ~/dev/Audio/audio.mp3 --language English \ 
	--task transcribe --model base -o ~/dev/Text 
EOF

We now have succesfully transcribed a video and have text. Now what?

Check out whisper repo for more usage examples!


This Section is a work in progress

Add your API key to a .py file that is imported.

$ cat <<EOF > apiKey.py apiKeyOAI = '$YOUR KEY HERE' EOF

ToDo:

Cleanup .py file with API call to Completion endpoint.

@Jeremy-Gstein
Copy link
Author

Jeremy-Gstein commented Dec 24, 2022

quick notes on some neat things you can do with whisper. Still need to clean this up in future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment