Utility Functions¶
VOICEBOX configuration, filesystem helpers, numeric routines, and combinatorics.
VOICEBOX configuration and environment¶
v_voicebox
¶
V_VOICEBOX - Global parameters for Voicebox functions.
Set/get global parameters used by other functions in the VOICEBOX toolbox.
v_voicebox
¶
Get or set global Voicebox parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Parameter name. If None, returns all parameters. |
None
|
value
|
optional
|
New value for the parameter. |
None
|
Returns:
| Type | Description |
|---|---|
Result depends on inputs:
|
|
Source code in pyvoicebox/v_voicebox.py
v_voicebox_update
¶
V_VOICEBOX_UPDATE - Check for voicebox updates (stub).
v_voicebox_update
¶
Check for voicebox updates.
This is a stub. The MATLAB version checks for toolbox updates. In the Python port, use pip for package management.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always raised as this is a MATLAB-specific function. |
Source code in pyvoicebox/v_voicebox_update.py
v_paramsetch
¶
V_PARAMSETCH - Set parameters for speech processing algorithms (stub).
v_paramsetch
¶
Set parameters for speech processing algorithms.
The full MATLAB implementation handles parameter sets for various speech processing configurations. A stub is provided.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Full implementation pending. |
Source code in pyvoicebox/v_paramsetch.py
v_hostipinfo
¶
V_HOSTIPINFO - Get host name and IP info using Python equivalents.
v_hostipinfo
¶
Get host name and IP address info.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
str
|
Mode string. 'h' for hostname, 'i' for IP address. |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
info |
str
|
Hostname or IP address. |
Source code in pyvoicebox/v_hostipinfo.py
v_winenvar
¶
V_WINENVAR - Read Windows environment variable (stub).
v_winenvar
¶
Read a Windows environment variable.
This is a cross-platform stub that uses os.environ.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Environment variable name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
value |
str or None
|
Value of the environment variable, or None if not found. |
Source code in pyvoicebox/v_winenvar.py
v_unixwhich
¶
V_UNIXWHICH - Search system path for an executable (Python equivalent).
v_unixwhich
¶
Search system path for an executable program.
Uses Python's shutil.which() as a cross-platform equivalent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c
|
str
|
Name of file to search for. |
required |
e
|
str
|
Extensions to search (ignored; shutil.which handles this). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
f |
str or None
|
Full pathname of executable, or None if not found. |
Source code in pyvoicebox/v_unixwhich.py
v_regexfiles
¶
V_REGEXFILES - Find files matching a regular expression pattern.
v_regexfiles
¶
Find files matching a regular expression pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
Regular expression pattern to match filenames. |
required |
directory
|
str
|
Directory to search. Default is current directory. |
'.'
|
recursive
|
bool
|
If True, search recursively. Default False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
files |
list of str
|
List of matching file paths. |
Source code in pyvoicebox/v_regexfiles.py
v_fopenmkd
¶
V_FOPENMKD - Open file, creating directories if needed.
v_fopenmkd
¶
Open a file, creating any missing parent directories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to file. |
required |
mode
|
str
|
File open mode (default 'r'). |
'r'
|
**kwargs
|
Additional arguments passed to open(). |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
fid |
file object
|
Open file handle. |
Source code in pyvoicebox/v_fopenmkd.py
v_finishat
¶
V_FINISHAT - Print estimated finish time of a long computation.
v_finishat
¶
Print estimated finish time of a long computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frac
|
float or ndarray
|
Fraction of total computation completed (0 to 1). 0 initializes the timer. |
required |
tol
|
float
|
Tolerance in minutes before reprinting. |
None
|
fmt
|
str
|
Format string. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
eta |
str
|
Estimated finish time string. |
Source code in pyvoicebox/v_finishat.py
v_m2htmlpwd
¶
V_M2HTMLPWD - MATLAB-specific HTML documentation utility (stub).
v_m2htmlpwd
¶
Generate HTML documentation from MATLAB m-files.
This is a MATLAB-specific function and has no Python equivalent.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always raised as this is MATLAB-specific. |
Source code in pyvoicebox/v_m2htmlpwd.py
Numerical helpers¶
v_atan2sc
¶
V_ATAN2SC - sin and cosine of atan(y/x).
v_atan2sc
¶
Compute sin and cosine of atan(y/x) robustly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
array_like
|
Input values (same shape). |
required |
x
|
array_like
|
Input values (same shape). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
s |
ndarray
|
sin(t) where tan(t) = y/x |
c |
ndarray
|
cos(t) where tan(t) = y/x |
r |
ndarray
|
sqrt(x^2 + y^2) |
t |
ndarray
|
atan2(y, x) |
Source code in pyvoicebox/v_atan2sc.py
v_logsum
¶
V_LOGSUM - log(sum(k.*exp(x),d)) computed avoiding overflow/underflow.
v_logsum
¶
Compute log(sum(k.*exp(x), d)) avoiding overflow/underflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
Data array. |
required |
d
|
int
|
Axis to sum along. Default: first non-singleton dimension. |
None
|
k
|
array_like
|
Scaling array (same shape as x, or vector along axis d). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
y |
ndarray
|
log(sum(k.*exp(x), d)) |
Source code in pyvoicebox/v_logsum.py
v_gammalns
¶
V_GAMMALNS - Log of Gamma(x) for positive or negative real x.
v_gammalns
¶
Compute log(|Gamma(x)|) and optionally sign(Gamma(x)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
Real input values. |
required |
return_sign
|
bool
|
If True, return (y, s) where s = sign(Gamma(x)). If False (default), return y which may be complex for negative Gamma. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
y |
ndarray
|
log(|Gamma(x)|) if return_sign=True, else log(Gamma(x)) (complex where needed). |
s |
ndarray (only if return_sign=True)
|
sign(Gamma(x)) |
Source code in pyvoicebox/v_gammalns.py
v_hypergeom1f1
¶
V_HYPERGEOM1F1 - Confluent hypergeometric function 1F1 (Kummer's M).
v_hypergeom1f1
¶
Confluent hypergeometric function 1F1(a; b; z) = M(a; b; z).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
First parameter (real scalar). |
required |
b
|
float
|
Second parameter (real scalar). |
required |
z
|
array_like
|
Input values (real). |
required |
tol
|
float
|
Tolerance. Default 1e-10. |
1e-10
|
maxj
|
int
|
Maximum iterations. Default 500. |
500
|
th
|
float
|
Threshold for algorithm selection. Default 30. |
30
|
Returns:
| Name | Type | Description |
|---|---|---|
h |
ndarray
|
Output values. |
l |
ndarray
|
Number of iterations used. |
Source code in pyvoicebox/v_hypergeom1f1.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
v_dualdiag
¶
V_DUALDIAG - Simultaneous diagonalization of two Hermitian matrices.
v_dualdiag
¶
Simultaneous diagonalization of two Hermitian matrices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
(array_like, shape(n, n))
|
Hermitian matrix. |
required |
b
|
(array_like, shape(n, n))
|
Hermitian matrix. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
a |
(ndarray, shape(n, n))
|
Diagonalizing matrix. |
d |
(ndarray, shape(n))
|
Real diagonal elements: A'BA = diag(D). |
e |
(ndarray, shape(n))
|
Real diagonal elements: A'WA = diag(E). |
Source code in pyvoicebox/v_dualdiag.py
v_mintrace
¶
V_MINTRACE - Find row permutation to minimize trace.
v_mintrace
¶
Find row permutation to minimize trace of x(p,:).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(array_like, shape(n, n))
|
Square real-valued matrix. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
p |
(ndarray, shape(n))
|
Row permutation that minimizes trace(x[p, :]). |
Source code in pyvoicebox/v_mintrace.py
v_quadpeak
¶
V_QUADPEAK - Find quadratically-interpolated peak in an N-D array.
v_quadpeak
¶
Find quadratically-interpolated peak in an N-D array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
array_like
|
Input array (at least 3 elements in each non-singleton dimension). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
v |
float
|
Peak value. |
x |
ndarray
|
Position of peak (fractional subscript values, 1-based). |
t |
int
|
-1 for maximum, 0 for saddle point, +1 for minimum. |
m |
ndarray
|
Matrix defining the fitted quadratic. |
Source code in pyvoicebox/v_quadpeak.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
v_peak2dquad
¶
V_PEAK2DQUAD - Find quadratically-interpolated peak in a 2D array.
v_peak2dquad
¶
Find quadratically-interpolated peak in a 2D array.
This is a wrapper around v_quadpeak.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
(array_like, shape(m, n))
|
Input 2D array. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
v |
float
|
Peak value. |
xy |
ndarray
|
Position of peak. |
t |
int
|
-1 for maximum, 0 for saddle point, +1 for minimum. |
m |
ndarray
|
Fitted quadratic matrix. |
Source code in pyvoicebox/v_peak2dquad.py
Combinatorics and sorting¶
v_choosenk
¶
V_CHOOSENK - All choices of K elements from 0:N-1.
v_choosenk
¶
Generate all choices of K elements from 0:N-1 in lexical order.
Note: Returns 0-based indices (unlike MATLAB's 1-based).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Range of elements (0 to n-1). |
required |
k
|
int
|
Number of elements to choose. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
x |
ndarray of shape (C(n,k), k)
|
Each row is a combination. |
Source code in pyvoicebox/v_choosenk.py
v_choosrnk
¶
V_CHOOSRNK - All choices of K elements from 0:N-1 with replacement.
v_choosrnk
¶
Generate all choices of K elements from 0:N-1 with replacement.
Note: Returns 0-based indices (unlike MATLAB's 1-based).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Range of elements (0 to n-1). |
required |
k
|
int
|
Number of elements to choose. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
x |
ndarray
|
Each row is a combination with replacement. |
Source code in pyvoicebox/v_choosrnk.py
v_permutes
¶
V_PERMUTES - All N! permutations of 0:N-1 + signatures.
v_permutes
¶
Generate all N! permutations of 0:N-1 in lexical order.
Note: Returns 0-based indices (unlike MATLAB's 1-based).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of elements to permute. |
required |
return_sign
|
bool
|
If True, also return the signature of each permutation. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
p |
ndarray of shape (n!, n)
|
Each row is a permutation. |
s |
ndarray of shape (n!,), optional
|
Signature (+1 or -1) of each permutation. |
Source code in pyvoicebox/v_permutes.py
v_sort
¶
V_SORT - Sort with forward and inverse index.
v_sort
¶
Sort array with forward and optional inverse index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
array_like
|
Input vector or matrix (sorted along axis 0 for matrices). |
required |
descend
|
bool
|
Sort in descending order. |
False
|
return_inverse
|
bool
|
If True, also return the inverse index j such that a = b[j]. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
b |
ndarray
|
Sorted array. |
i |
ndarray
|
Forward index: b = a[i]. |
j |
ndarray (only if return_inverse=True)
|
Inverse index: a = b[j]. |