Audio File Input/Output¶
Read and write a variety of audio file formats.
Read and write¶
v_readwav
¶
V_READWAV - Read a .WAV format sound file.
Uses the soundfile library for core WAV I/O, preserving the MATLAB function signature for compatibility.
v_readwav
¶
Read a .WAV format sound file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the WAV file (with or without .wav extension). |
required |
mode
|
str
|
Scaling mode string. Default is 'p'. 'p' : Scaled so +-1 equals full scale (default). 'r' : Raw unscaled data (integer values). 's' : Auto scale to make data peak = +-1. 'q' : Scaled to make 0dBm0 be unity mean square. |
'p'
|
nmax
|
int
|
Maximum number of samples to read. -1 for unlimited (default). |
-1
|
nskip
|
int
|
Number of samples to skip from start. Default is 0. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
y |
ndarray
|
Data matrix of shape (samples, channels). |
fs |
int
|
Sample frequency in Hz. |
Source code in pyvoicebox/v_readwav.py
v_writewav
¶
V_WRITEWAV - Write a .WAV format sound file.
Uses the soundfile library for core WAV I/O.
v_writewav
¶
Write a .WAV format sound file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
array_like
|
Data to write. Shape (samples,) or (samples, channels). |
required |
fs
|
int
|
Sample frequency in Hz. |
required |
filename
|
str
|
Output filename (with or without .wav extension). |
required |
mode
|
str
|
Mode string controlling format and scaling. Default is 's'. 's' : Auto scale to make data peak = +-1 (default). 'r' : Raw unscaled data. 'p' : Scaled so +-1 equals full scale. 'q' : Scaled to 0dBm0. '16': 16 bit PCM data (default bit depth). '8' : 8 bit PCM data. '24': 24 bit PCM data. '32': 32 bit PCM data. 'v' : 32-bit floating point. 'V' : 64-bit floating point. 'a' : 8-bit A-law PCM. 'u' : 8-bit mu-law PCM. |
's'
|
Source code in pyvoicebox/v_writewav.py
v_readhtk
¶
V_READHTK - Read an HTK parameter file.
v_readhtk
¶
Read an HTK parameter file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
Path to the HTK file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
d |
ndarray
|
Data: column vector for waveforms, one row per frame for other types. |
fp |
float
|
Frame period in seconds. |
dt |
int
|
Base data type (0-12). |
tc |
int
|
Full type code including modifiers. |
t |
str
|
Text version of type code, e.g. 'LPC_C_K'. |
Source code in pyvoicebox/v_readhtk.py
v_writehtk
¶
V_WRITEHTK - Write data in HTK format.
v_writehtk
¶
Write data in HTK format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
Path to the output file. |
required |
d
|
array_like
|
Data to write: one row per frame. |
required |
fp
|
float
|
Frame period in seconds. |
required |
tc
|
int
|
Type code (see v_readhtk for details). |
required |
Source code in pyvoicebox/v_writehtk.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 | |
Read only¶
v_readsph
¶
V_READSPH - Read a SPHERE/TIMIT format sound file.
The SPHERE (SPeech HEader REsources) format is used by NIST for speech corpora like TIMIT.
v_readsph
¶
Read a SPHERE/TIMIT format sound file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the SPH file (with or without .sph extension). |
required |
mode
|
str
|
Scaling/format mode string. Default is 'p'. 'p' : Scaled so +-1 equals full scale (default). 'r' : Raw unscaled data (integer values). 's' : Auto scale to make data peak = +-1. 'l' : Force little endian byte order. 'b' : Force big endian byte order. 'w' : Also read .wrd annotation file. 't' : Also read .phn phonetic transcription file. |
'p'
|
nmax
|
int
|
Maximum number of samples to read. -1 for unlimited. |
-1
|
nskip
|
int
|
Number of samples to skip from start. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
y |
ndarray
|
Data matrix of shape (samples, channels). |
fs |
int
|
Sample frequency in Hz. |
wrd |
list of tuple, optional
|
Word annotations [(start_time, end_time, text), ...]. Only returned if 'w' in mode. |
phn |
list of tuple, optional
|
Phoneme annotations [(start_time, end_time, text), ...]. Only returned if 't' in mode. |
ffx |
dict
|
File information dictionary. |
Source code in pyvoicebox/v_readsph.py
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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
v_readaif
¶
V_READAIF - Read a .AIF (AIFF) format sound file.
Uses the soundfile library when available for robust AIFF reading.
v_readaif
¶
Read a .AIF (AIFF) format sound file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the AIF file (with or without .aif extension). |
required |
mode
|
str
|
Scaling mode string. Default is 'p'. 'p' : Scaled so +-1 equals full scale (default). 'r' : Raw unscaled data (integer values). 's' : Auto scale to make data peak = +-1. |
'p'
|
nmax
|
int
|
Maximum number of samples to read. -1 for unlimited (default). |
-1
|
nskip
|
int
|
Number of samples to skip from start. Default is 0. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
y |
ndarray
|
Data matrix of shape (samples, channels). |
fs |
int
|
Sample frequency in Hz. |
Source code in pyvoicebox/v_readaif.py
v_readau
¶
V_READAU - Read a SUN .AU format sound file.
Uses the soundfile library for robust AU file reading.
v_readau
¶
Read a SUN .AU format sound file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the AU file (with or without .au extension). |
required |
mode
|
str
|
Mode string: 't' : trim leading and trailing silences 'h' : read header only |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
y |
ndarray
|
Data matrix with one channel per column. If mode='h', returns header parameters as a dict. |
fs |
int
|
Sample frequency in Hz. |
h |
dict
|
Header parameters: 'header_length', 'data_length', 'data_format', 'sample_rate', 'num_channels'. |
Source code in pyvoicebox/v_readau.py
v_readflac
¶
V_READFLAC - Read a .FLAC format sound file.
Uses the soundfile library for FLAC decoding.
v_readflac
¶
Read a .FLAC format sound file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the FLAC file. |
required |
mode
|
str
|
Scaling mode string. Default is 'p'. 'p' : Scaled so +-1 equals full scale (default). 'r' : Raw unscaled data (integer values). 's' : Auto scale to make data peak = +-1. |
'p'
|
Returns:
| Name | Type | Description |
|---|---|---|
y |
ndarray
|
Data matrix of shape (samples, channels). |
fs |
int
|
Sample frequency in Hz. |
Source code in pyvoicebox/v_readflac.py
v_readsfs
¶
V_READSFS - Read a .SFS (Speech Filing System) format sound file.
The SFS format was developed by Mark Huckvale at UCL for speech research. This is a simplified Python reader for the most common data types.
v_readsfs
¶
Read a .SFS format sound file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the SFS file. |
required |
ty
|
int
|
Type of data item: 0=main header, 1=speech, 2=laryngograph, 5=annotation. Default is 1. |
1
|
sub
|
int
|
Instance of type ty: 0=first, -1=last (default). |
-1
|
mode
|
str
|
Mode string. Default is 'p'. 'i' : Force integer data to be at least 16 bits. |
'p'
|
nmax
|
int
|
Maximum number of samples to read. -1 for unlimited. |
-1
|
nskip
|
int
|
Number of samples to skip from start. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
y |
ndarray
|
Data array. For speech data, column vector. |
fs |
float
|
Sample frequency in Hz. |
hd |
dict
|
Header information. |
Source code in pyvoicebox/v_readsfs.py
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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
v_readcnx
¶
V_READCNX - Read a .CNX format sound file.
This is the format of the BT Connex-S1 alphabet database.
v_readcnx
¶
Read a .CNX format sound file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the CNX file (with or without .cnx extension). |
required |
mode
|
str
|
Mode string: 't' : trim to start/end samples indicated in header 'h' : read header only |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
y |
ndarray
|
Column vector containing the waveform (int16 samples). |
fs |
float
|
Sample frequency in Hz. |
h |
dict
|
Header parameters: 'num_samples' : number of samples in file 'status' : 0=good, 1=bad 'start_sample' : start sample number 'end_sample' : ending sample number 'speaker_id' : speaker identification number 'speaker_age' : speaker age group 'speaker_sex' : 0=male, 1=female 'ascii_char' : ascii character 'repetition' : repetition number |
Source code in pyvoicebox/v_readcnx.py
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 122 123 124 125 126 127 128 129 130 131 132 133 134 | |