media

package
v0.101.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package media provides multimedia processing for chat apps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectMIMEType

func DetectMIMEType(data []byte) string

DetectMIMEType detects the MIME type of data.

func GetFileExtension

func GetFileExtension(mimeType string) string

GetFileExtension returns the file extension for a MIME type.

Types

type MediaConfig

type MediaConfig struct {
	// Whisper (voice-to-text)
	WhisperEndpoint string
	WhisperAPIKey   string

	// OCR (image text extraction)
	OCREngine string // "tesseract" or "api"
	OCRBin    string // Path to tesseract binary (if using local)

	// Limits
	MaxPhotoSizeMB    int64
	MaxDocumentSizeMB int64
	MaxAudioSizeMB    int64
	MaxVideoSizeMB    int64
}

MediaConfig holds configuration for media processing.

type MediaHandler

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

MediaHandler processes multimedia messages.

func NewMediaHandler

func NewMediaHandler(config *MediaConfig) *MediaHandler

NewMediaHandler creates a new media handler.

func (*MediaHandler) ProcessAudio

func (h *MediaHandler) ProcessAudio(ctx context.Context, data []byte, mimeType string) (string, error)

ProcessAudio converts audio data to text using Whisper API.

func (*MediaHandler) ProcessImage

func (h *MediaHandler) ProcessImage(ctx context.Context, data []byte) (string, error)

ProcessImage extracts text from images using OCR.

func (*MediaHandler) SaveTempFile

func (h *MediaHandler) SaveTempFile(data []byte, ext string) (string, error)

SaveTempFile saves data to a temporary file and returns the path.

func (*MediaHandler) ValidateAudioSize

func (h *MediaHandler) ValidateAudioSize(size int64) error

ValidateAudioSize checks if audio is within size limits.

func (*MediaHandler) ValidateDocumentSize

func (h *MediaHandler) ValidateDocumentSize(size int64) error

ValidateDocumentSize checks if document is within size limits.

func (*MediaHandler) ValidatePhotoSize

func (h *MediaHandler) ValidatePhotoSize(size int64) error

ValidatePhotoSize checks if photo is within size limits.

type WhisperResponse

type WhisperResponse struct {
	Text     string  `json:"text"`
	Language string  `json:"language,omitempty"`
	Duration float64 `json:"duration,omitempty"`
	Words    []struct {
		Word  string  `json:"word"`
		Start float64 `json:"start"`
		End   float64 `json:"end"`
	} `json:"words,omitempty"`
}

WhisperResponse represents the Whisper API response.

Jump to

Keyboard shortcuts

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