scriber

package module
v0.0.0-...-5d8a3ce Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 10 Imported by: 0

README

Scriber

Scriber is a Go service that processes audio files and transcribes them into subtitles or transcripts using the Whisper API.

Features

  • Convert audio files to WAV format using ffmpeg
  • Transcribe audio files into subtitles (.srt) or transcripts (.txt)
  • Supports multiple languages

Installation

  1. Clone the repository:

    git clone https://github.com/alesr/scriber.git
    cd scriber
    
  2. Install dependencies:

    go mod download
    
  3. Ensure ffmpeg is installed on your system:

    # On macOS
    brew install ffmpeg
    
    # On Ubuntu
    sudo apt-get install ffmpeg
    

Usage

Example
package main

import (
    "context"
    "os"
    "log/slog"

    "github.com/alesr/scriber"
    "github.com/alesr/whisperclient"
)

func main() {
    logger := slog.Default()
    whisperCli := whisperclient.NewClient("your-api-key")

    s := scriber.New(logger, whisperCli)

    inputFile, err := os.Open("path/to/example.mp4")
    if err != nil {
        logger.Error("Failed to open input file", slog.Error(err))
        os.Exit(1)
    }
    defer inputFile.Close()

    input := scriber.Input{
        Name:       "example.mp4",
        OutputType: scriber.OutputTypeSubtitles,
        Language:   "en",
        Data:       inputFile,
    }

    ctx := context.Background()
    if err := s.Process(ctx, input); err != nil {
        logger.Error("Failed to process file", slog.Error(err))
        os.Exit(1)
    }

    for result := range s.Collect() {
        logger.Info("Transcription result", slog.String("file", result.Name), slog.String("text", string(result.Text)))
    }
}

Testing

Run the tests:

go test ./...

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataError

type DataError struct{ E }

type E

type E string

E is an error type that implements the error interface.

func (E) Error

func (e E) Error() string

type ExtRequiredError

type ExtRequiredError struct{ E }

type Input

type Input struct {
	Name       string
	OutputType OutputType
	Language   string
	Data       io.ReadCloser
}

Input represents an input file to be processed.

type LanguageError

type LanguageError struct{ E }

type NameRequiredError

type NameRequiredError struct{ E }

type Output

type Output struct {
	Name string
	Text []byte
}

Output represents the result of processing an input file.

type OutputType

type OutputType string

OutputType represents the type of output to generate.

const (
	OutputTypeSubtitles  OutputType = "subtitles"
	OutputTypeTranscript OutputType = "transcript"
)

type OutputTypeError

type OutputTypeError struct{ E }

type Scriber

type Scriber struct {
	// contains filtered or unexported fields
}

Scriber is a service that processes audio files and transcribes them.

func New

func New(logger *slog.Logger, whisperCli whisperClient) *Scriber

func (*Scriber) Collect

func (s *Scriber) Collect() <-chan Output

func (*Scriber) Process

func (s *Scriber) Process(ctx context.Context, in Input) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL