hasabai

package module
v0.0.0-...-d882b57 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: MIT Imports: 8 Imported by: 0

README

Hasab AI Golang SDK

Unofficial Golang SDK for Hasab AI API (Audio transcription, translation, TTS, and more)

How to Use It

1. Installation
    go get github.com/itsllyaz/hasab-ai-golang
2. Setup
    package main

    import (
        "os"
        "github.com/itsllyaz/hasab-ai-golang"
    )

    func main(){
        client := hasabai.New(os.Getenv("HASAB_API_KEY"))
        fmt.Println("Hasab client initialized:", client)
    }
3. Upload Audio & Transcription
    resp, err := client.TranscribeAudio("audio.mp3", "eng")
    if err != nil {
        fmt.Println("Transcription error:", err)
        return
    }

    fmt.Printf("Transcription result: %+v\n", resp)

4. Upload Audio & Translation
    resp, err := client.TranslateAudio("audio.mp3", "eng", "amh")
    if err != nil {
        fmt.Println("Translation error:", err)
        return
    }

    fmt.Printf("Translation result: %+v\n", resp)


5. Fetch Hasab History
    history, err := client.HasabHistory()
    if err != nil {
        fmt.Println("Error fetching history:", err)
        return
    }
    fmt.Printf("History: %+v\n", history)


6. TTS & Analytics
    ttsHistory, err := client.TTSHistory()
    if err != nil {
        fmt.Println("TTS history error:", err)
        return
    }
    fmt.Printf("TTS history: %+v\n", ttsHistory)

Resources

Contributions

  • wat r u waiting....

Documentation

Index

Constants

View Source
const (
	HasabHistoryV1URL              = "https://hasab.co/api/v1/chat/history"
	HasabTranscriptionHistoryV1URL = "https://hasab.co/api/v1/audios"
	HasabTranscriptionV1URL        = "https://hasab.co/api/v1/upload-audio"
	HasabTranslationsHistoryV1URL  = "https://hasab.co/api/v1/translations"
	HasabSpeakersV1URL             = "https://hasab.co/api/v1/tts/speakers"
	TTSHistoryV1URL                = "https://hasab.co/api/v1/tts/history"
	TTSAnalyticsV1URL              = "https://hasab.co/api/v1/tts/analytics"
	TTSRecordV1URL                 = "https://hasab.co/api/v1/tts/record"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatHistory

type ChatHistory struct {
	ID       int       `json:"id"`
	Title    string    `json:"title"`
	Messages []Message `json:"messages"`
}

type Client

type Client struct {
	ApiKey string
}

func New

func New(apiKey string) *Client

func (*Client) CallHasab

func (c *Client) CallHasab(url string, target any) error

func (*Client) HasabHistory

func (c *Client) HasabHistory() (*HasabResponse, error)

func (*Client) HasabSpeakers

func (c *Client) HasabSpeakers() (*HasabSpeakersResponse, error)

func (*Client) HasabTranscriptionHistory

func (c *Client) HasabTranscriptionHistory() (*HasabTranscriptionResponse, error)

func (*Client) HasabTranslationsHistory

func (c *Client) HasabTranslationsHistory() (*HasabTranslationsResponse, error)

func (*Client) TTSAnalytics

func (c *Client) TTSAnalytics() (*TTSAnalyticsResponse, error)

func (*Client) TTSHistory

func (c *Client) TTSHistory() (*TTSHistoryResponse, error)

func (*Client) TTSRecord

func (c *Client) TTSRecord(recordID int) (*TTSRecordResponse, error)

func (*Client) TranscribeAudio

func (c *Client) TranscribeAudio(filePath, sourceLanguage string) (*UploadAudioResponse, error)

helper for transcription only

func (*Client) TranslateAudio

func (c *Client) TranslateAudio(filePath, sourceLanguage, targetLanguage string) (*UploadAudioResponse, error)

helper for transcription + translation

func (*Client) UploadAudio

func (c *Client) UploadAudio(filePath string, transcribe, translate bool, targetLanguage, sourceLanguage string) (*UploadAudioResponse, error)

type HasabAI

type HasabAI interface {
	HasabHistory() (*HasabResponse, error)
	HasabTranscriptionHistory() (*HasabTranscriptionResponse, error)
	HasabTranslationsHistory() (*HasabTranslationsResponse, error)
	HasabSpeakers() (*HasabSpeakersResponse, error)
	TTSHistory() (*TTSHistoryResponse, error)
	TTSAnalytics() (*TTSAnalyticsResponse, error)
	TTSRecord() (TTSRecordResponse, error)
}

type HasabResponse

type HasabResponse struct {
	History []ChatHistory `json:"history"`
	Success bool          `json:"success"`
}

type HasabSpeakersResponse

type HasabSpeakersResponse struct {
	Languages struct {
		Amh []string `json:"amh"`
		Orm []string `json:"orm"`
		Tir []string `json:"tir"`
	} `json:"languages"`
	Success       bool `json:"success"`
	TotalSpeakers int  `json:"total_speakers"`
}

type HasabTranscriptionResponse

type HasabTranscriptionResponse struct {
	ID               int    `json:"id"`
	Filename         string `json:"filename"`
	OriginalFilename string `json:"original_filename"`
	MimeType         string `json:"mime_type"`
	DurationSeconds  string `json:"duration_in_seconds"`
	Description      string `json:"description"`
	Success          bool   `json:"success"`
	Transcription    string `json:"transcription"`
	Translation      string `json:"translation"`
	Summary          string `json:"summary"`
	AudioType        string `json:"audio_type"`
	CreatedAt        string `json:"created_at"`
	User             User   `json:"user"`
}

type HasabTranslationsResponse

type HasabTranslationsResponse struct {
	Success         bool   `json:"success"`
	Message         string `json:"message"`
	ChargeMessage   string `json:"charge_message"`
	RemainingTokens int    `json:"remaining_tokens"`
	TokensCharged   int    `json:"tokens_charged"`
	Summary         string `json:"summary"`
	Timestamp       []any  `json:"timestamp"`

	Audio struct {
		ID               int    `json:"id"`
		UserID           int    `json:"user_id"`
		Filename         string `json:"filename"`
		OriginalFilename string `json:"original_filename"`
		Path             string `json:"path"`
		MimeType         string `json:"mime_type"`
		FileSize         string `json:"file_size"`
		DurationSeconds  int    `json:"duration_in_seconds"`
		Description      string `json:"description"`
		IsMeeting        bool   `json:"is_meeting"`
		Summary          string `json:"summary"`
		Transcription    string `json:"transcription"`
		Translation      string `json:"translation"`
		CreatedAt        string `json:"created_at"`
		UpdatedAt        string `json:"updated_at"`
	} `json:"audio"`

	Metadata struct {
		TokensCharged   int    `json:"tokens_charged"`
		RemainingTokens int    `json:"remaining_tokens"`
		ChargeMessage   string `json:"charge_message"`
	} `json:"metadata"`
}

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type TTSAnalyticsResponse

type TTSAnalyticsResponse struct {
	TotalRequests           int            `json:"total_requests"`
	SuccessfulRequests      int            `json:"successful_requests"`
	Success                 bool           `json:"success"`
	FailedRequests          int            `json:"failed_requests"`
	TotalTokensUsed         int            `json:"total_tokens_used"`
	AverageTokensPerRequest float64        `json:"average_tokens_per_request"`
	LanguageBreakdown       map[string]int `json:"language_breakdown"`
	DailyUsage              []struct {
		Date       string `json:"date"`
		Requests   int    `json:"requests"`
		TokensUsed int    `json:"tokens_used"`
	} `json:"daily_usage"`
}

type TTSHistoryResponse

type TTSHistoryResponse struct {
	Records []struct {
		ID          int    `json:"id"`
		Text        string `json:"text"`
		Language    string `json:"language"`
		SpeakerName string `json:"speaker_name"`
		Status      string `json:"status"`
		AudioURL    string `json:"audio_url"`
		TokensUsed  int    `json:"tokens_used"`
		CreatedAt   string `json:"created_at"`
	} `json:"records"`
	Total   int  `json:"total"`
	Limit   int  `json:"limit"`
	Success bool `json:"success"`
	Offset  int  `json:"offset"`
}

type TTSRecordResponse

type TTSRecordResponse struct {
	Success bool `json:"success"`
	Record  struct {
		ID          int    `json:"id"`
		Text        string `json:"text"`
		Language    string `json:"language"`
		SpeakerName string `json:"speaker_name"`
		Status      string `json:"status"`
		AudioURL    string `json:"audio_url"`
		TokensUsed  int    `json:"tokens_used"`
		CreatedAt   string `json:"created_at"`
	} `json:"record"`
}

type UploadAudioResponse

type UploadAudioResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
	Audio   struct {
		Transcription string `json:"transcription"`
		Translation   string `json:"translation"`
	} `json:"audio"`
}

type User

type User struct {
	ID    int    `json:"id"`
	Name  string `json:"name"`
	Email string `json:"email"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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