initial commit
This commit is contained in:
commit
c094b5770c
113 changed files with 6879 additions and 0 deletions
22
pkgs/transcribe/default.nix
Normal file
22
pkgs/transcribe/default.nix
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
python3Packages,
|
||||
...
|
||||
}:
|
||||
|
||||
python3Packages.buildPythonApplication {
|
||||
pname = "transcribe";
|
||||
version = "1.0.0";
|
||||
|
||||
src = ./.;
|
||||
pyproject = true;
|
||||
|
||||
build-system = [ python3Packages.setuptools ];
|
||||
|
||||
propagatedBuildInputs = [ python3Packages.openai ];
|
||||
|
||||
doCheck = false;
|
||||
|
||||
meta = {
|
||||
description = "Transcribe a given audio file using the OpenAI API.";
|
||||
};
|
||||
}
|
||||
7
pkgs/transcribe/setup.py
Normal file
7
pkgs/transcribe/setup.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='transcribe',
|
||||
version='1.0.0',
|
||||
scripts=['transcribe'],
|
||||
)
|
||||
47
pkgs/transcribe/transcribe
Normal file
47
pkgs/transcribe/transcribe
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import os
|
||||
from openai import OpenAI
|
||||
|
||||
def transcribe_audio(file_path):
|
||||
"""Transcribe the given audio file using OpenAI API."""
|
||||
if not os.environ.get("OPENAI_API_KEY"):
|
||||
print("Error: OPENAI_API_KEY environment variable is not set.")
|
||||
return None
|
||||
|
||||
if not os.path.exists(file_path):
|
||||
print(f"Error: File '{file_path}' not found.")
|
||||
return None
|
||||
|
||||
try:
|
||||
client = OpenAI()
|
||||
|
||||
with open(file_path, "rb") as audio_file:
|
||||
transcription = client.audio.transcriptions.create(
|
||||
# model="gpt-4o-transcribe",
|
||||
model="whisper-1",
|
||||
file=audio_file,
|
||||
response_format="text"
|
||||
)
|
||||
|
||||
return transcription
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error occurred during transcription: {e}")
|
||||
return None
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: transcribe <audio_file_path>")
|
||||
sys.exit(1)
|
||||
|
||||
audio_file_path = sys.argv[1]
|
||||
|
||||
transcription = transcribe_audio(audio_file_path)
|
||||
|
||||
if transcription:
|
||||
print(transcription)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue