Utilities¶
The olaverse.utils module provides global constants, currency formatting, and audio I/O helpers used throughout the library and available for your own use.
Currency Formatting¶
format_currency¶
Format any numeric value as a currency string with the correct symbol.
from olaverse.utils import format_currency
format_currency(1500, "₦") # → '₦1,500.00'
format_currency(3_750_000, "₦") # → '₦3,750,000.00'
format_currency(99.9, "$") # → '$99.90'
format_currency("invalid", "£") # → '£invalid'
olaverse.utils.format_currency ¶
Format a number or string as a generic currency. e.g. format_currency(1500, "$") -> $1,500.00
CURRENCIES¶
A dictionary mapping ISO 4217 currency codes to their symbols. Includes the Nigerian Naira and major world currencies.
from olaverse.utils import CURRENCIES
CURRENCIES["NGN"] # → '₦'
CURRENCIES["USD"] # → '$'
CURRENCIES["GBP"] # → '£'
CURRENCIES["EUR"] # → '€'
# Use with format_currency
amount = 5_000
symbol = CURRENCIES["NGN"]
format_currency(amount, symbol) # → '₦5,000.00'
| Code | Currency | Symbol |
|---|---|---|
| NGN | Nigerian Naira | ₦ |
| USD | US Dollar | $ |
| GBP | British Pound | £ |
| EUR | Euro | € |
| JPY | Japanese Yen | ¥ |
| ZAR | South African Rand | R |
| INR | Indian Rupee | ₹ |
| BRL | Brazilian Real | R$ |
CONTINENTS¶
ISO continent codes mapped to full names.
from olaverse.utils import CONTINENTS
CONTINENTS["AF"] # → 'Africa'
CONTINENTS["EU"] # → 'Europe'
CONTINENTS["NA"] # → 'North America'
Audio I/O¶
Standard read/write helpers for .wav files. Useful when working with the speech pipeline or external TTS models.
save_audio¶
import numpy as np
from olaverse.utils import save_audio
# Save a generated waveform (e.g. from a vocoder)
waveform = np.zeros(22050, dtype=np.float32) # 1 second of silence
save_audio(waveform, sample_rate=22050, output_path="output/test.wav")
olaverse.utils.save_audio ¶
Save a generated audio waveform to a .wav file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
waveform
|
object
|
1D numpy array representing the audio signal. |
required |
sample_rate
|
int
|
The sampling rate (e.g., 22050 or 24000). |
required |
output_path
|
str
|
Path to save the audio file. |
required |
load_audio¶
from olaverse.utils import load_audio
sample_rate, waveform = load_audio("path/to/audio.wav")
print(f"Sample rate: {sample_rate} Hz")
print(f"Duration: {len(waveform) / sample_rate:.2f}s")
print(f"Shape: {waveform.shape}")
olaverse.utils.load_audio ¶
Load an audio waveform from a .wav file.
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple
|
(sample_rate, waveform) |