Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
MPAI-Private
MPAI-CAE
arp
ARP Library
Commits
bcb8607c
Commit
bcb8607c
authored
Apr 09, 2023
by
Matteo
Browse files
update
parent
bd641223
Changes
5
Hide whitespace changes
Inline
Side-by-side
mpai_cae_arp/audio/_audio.py
View file @
bcb8607c
...
...
@@ -5,7 +5,7 @@ import numpy as np
import
librosa
from
mpai_cae_arp.audio._noise
import
Noise
import
mpai_cae_arp.audio
.utils
as
utils
from
mpai_cae_arp.audio
import
utils
class
AudioWave
:
...
...
@@ -486,4 +486,4 @@ class AudioWave:
idxs
[
min
(
noise_list
).
label
].
append
((
i
,
i
+
window_frames
))
i
+=
window_frames
return
idxs
\ No newline at end of file
return
idxs
mpai_cae_arp/files.py
View file @
bcb8607c
from
io
import
TextIOWrapper
from
enum
import
Enum
import
json
import
yaml
from
pydantic
import
BaseModel
def
get_file_content
(
file_name
:
str
,
format
:
str
)
->
dict
:
"""
Parameters
----------
file_name : str
the path to the file to read
format : str
the format of the file to read (yaml or json)
Raises
------
ValueError
if the format is not supported
Returns
-------
dict
the parsed content of the file
"""
with
open
(
file_name
)
as
fd
:
if
format
==
"yaml"
:
content
=
yaml
.
safe_load
(
fd
)
return
content
elif
format
==
"json"
:
content
=
json
.
load
(
fd
)
else
:
raise
ValueError
(
"Format not supported"
)
return
content
class
FileAction
(
Enum
):
READ
=
"r"
WRITE
=
"w"
APPEND
=
"a"
class
FileType
(
Enum
):
YAML
=
"yaml"
JSON
=
"json"
class
File
(
BaseModel
):
encoding
:
str
format
:
FileType
path
:
str
def
__init__
(
self
,
path
:
str
,
filetype
:
FileType
,
encoding
:
str
=
'utf-8'
):
super
().
__init__
(
path
=
path
,
format
=
filetype
,
encoding
=
encoding
)
def
open
(
self
,
action
:
FileAction
)
->
TextIOWrapper
:
"""
Open the file with the given action
Parameters
----------
action : FileAction
the action to perform on the file at opening
Returns
-------
TextIOWrapper
the file descriptor
"""
return
open
(
self
.
path
,
action
.
value
,
encoding
=
self
.
encoding
)
def
get_content
(
self
)
->
dict
:
"""
Return the file content
Raises
------
ValueError
if the format is not supported
Returns
-------
dict
the parsed content of the file
"""
with
self
.
open
(
FileAction
.
READ
)
as
fd
:
if
self
.
format
==
FileType
.
YAML
:
content
=
yaml
.
safe_load
(
fd
)
return
content
if
self
.
format
==
FileType
.
JSON
:
content
=
json
.
load
(
fd
)
else
:
raise
ValueError
(
"Format not supported"
)
return
content
def
write_content
(
self
,
content
:
dict
)
->
None
:
"""
Write the given content in the file
Parameters
----------
content : dict
the content to write in the file
"""
with
self
.
open
(
FileAction
.
WRITE
)
as
fd
:
if
self
.
format
==
FileType
.
YAML
:
yaml
.
safe_dump
(
content
,
fd
)
elif
self
.
format
==
FileType
.
JSON
:
json
.
dump
(
content
,
fd
)
else
:
raise
ValueError
(
"Format not supported"
)
mpai_cae_arp/io.py
View file @
bcb8607c
...
...
@@ -52,3 +52,20 @@ def prettify(text: str, color: Color = None, styles: list[Style] = None) -> str:
prepend
+=
style
.
value
return
prepend
+
text
+
END
def
pprint
(
text
:
str
,
color
:
Color
=
None
,
styles
:
list
[
Style
]
=
None
)
->
None
:
"""
Formats a string with some styles and prints it
Parameters
----------
text : str
string to format
color : Color, optional
color to use
styles : list[Style], optional
styles to use
"""
print
(
prettify
(
text
,
color
,
styles
))
mpai_cae_arp/types/irregularity.py
View file @
bcb8607c
import
uuid
from
enum
import
Enum
from
pydantic
import
BaseModel
,
Field
from
typing
import
Annotated
from
pydantic
import
BaseModel
,
Field
from
mpai_cae_arp.audio.standards
import
EqualizationStandard
,
SpeedStandard
...
...
@@ -119,38 +119,35 @@ class Irregularity(BaseModel):
class
IrregularityFile
(
BaseModel
):
# TODO: the offset calculation is not implemented yet, so it is set to None
irregularities
:
list
[
Irregularity
]
offset
:
Annotated
[
int
,
Field
(
gt
=
0
)]
|
None
irregularities
:
Annotated
[
list
[
Irregularity
]
,
Field
(
default
=
[])]
offset
:
Annotated
[
int
,
Field
(
default
=
0
)]
class
Config
:
schema_extra
=
{
"example"
:
{
"offset"
:
0
,
"irregularities"
:
[
{
"irregularity_ID"
:
"a0a0a0a0-a0a0-a0a0-a0a0-a0a0a0a0a0a0"
,
"source"
:
"a"
,
"time_label"
:
"00:00:00:00"
,
"irregularity_type"
:
"b"
,
"irregularity_properties"
:
{
"reading_speed"
:
"n"
,
"reading_equalisation"
:
"n"
,
"writing_speed"
:
"n"
,
"writing_equalisation"
:
"n"
},
"audio_block_URI"
:
"https://example.com/audio.wav"
,
}
]
"offset"
:
0
,
"irregularities"
:
[{
"irregularity_ID"
:
"a0a0a0a0-a0a0-a0a0-a0a0-a0a0a0a0a0a0"
,
"source"
:
"a"
,
"time_label"
:
"00:00:00:00"
,
"irregularity_type"
:
"b"
,
"irregularity_properties"
:
{
"reading_speed"
:
"n"
,
"reading_equalisation"
:
"n"
,
"writing_speed"
:
"n"
,
"writing_equalisation"
:
"n"
},
"audio_block_URI"
:
"https://example.com/audio.wav"
,
}]
}
}
def
__init__
(
self
,
irregularities
:
list
[
Irregularity
]
=
[],
offset
:
int
|
None
=
None
):
self
.
irregularities
=
irregularities
self
.
offset
=
offset
def
__eq__
(
self
,
__o
:
object
)
->
bool
:
if
not
isinstance
(
__o
,
IrregularityFile
):
return
False
...
...
pyproject.toml
View file @
bcb8607c
[tool.poetry]
name
=
"mpai-cae-arp"
version
=
"0.
1.0
"
version
=
"0.
2.1
"
description
=
"The MPAI CAE-ARP software API"
authors
=
[
"Matteo Spanio <dev2@audioinnova.com>"
]
readme
=
"README.md"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment