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
Audio Analyzer
Commits
41fb91b4
Commit
41fb91b4
authored
Apr 13, 2023
by
matteospanio
Browse files
update
parent
32789bf3
Changes
4
Hide whitespace changes
Inline
Side-by-side
poetry.lock
View file @
41fb91b4
# This file is automatically @generated by Poetry and should not be changed by hand.
# This file is automatically @generated by Poetry
1.4.0
and should not be changed by hand.
[[package]]
[[package]]
name = "alabaster"
name = "alabaster"
...
@@ -1033,6 +1033,21 @@ typing-extensions = ">=4.2.0"
...
@@ -1033,6 +1033,21 @@ typing-extensions = ">=4.2.0"
dotenv = ["python-dotenv (>=0.10.4)"]
dotenv = ["python-dotenv (>=0.10.4)"]
email = ["email-validator (>=1.0.3)"]
email = ["email-validator (>=1.0.3)"]
[[package]]
name = "pyee"
version = "9.0.4"
description = "A port of node.js's EventEmitter to python."
category = "main"
optional = false
python-versions = "*"
files = [
{file = "pyee-9.0.4-py2.py3-none-any.whl", hash = "sha256:9f066570130c554e9cc12de5a9d86f57c7ee47fece163bbdaa3e9c933cfbdfa5"},
{file = "pyee-9.0.4.tar.gz", hash = "sha256:2770c4928abc721f46b705e6a72b0c59480c4a69c9a83ca0b00bb994f1ea4b32"},
]
[package.dependencies]
typing-extensions = "*"
[[package]]
[[package]]
name = "pygments"
name = "pygments"
version = "2.15.0"
version = "2.15.0"
...
@@ -1107,6 +1122,22 @@ files = [
...
@@ -1107,6 +1122,22 @@ files = [
[package.dependencies]
[package.dependencies]
six = ">=1.5"
six = ">=1.5"
[[package]]
name = "python-ffmpeg"
version = "2.0.4"
description = "A python binding for FFmpeg which provides sync and async APIs"
category = "main"
optional = false
python-versions = ">=3.7"
files = [
{file = "python-ffmpeg-2.0.4.tar.gz", hash = "sha256:4d5275a58da2a82fb550acbf496ff86e76d677e06b781baeefbe05a4cd47ab50"},
{file = "python_ffmpeg-2.0.4-py3-none-any.whl", hash = "sha256:89aa9a0a6232a4fda58a9153af7d6c73b4d80d52b08dcde2b3c4ddcceb392b95"},
]
[package.dependencies]
pyee = "*"
typing-extensions = "*"
[[package]]
[[package]]
name = "pytz"
name = "pytz"
version = "2023.3"
version = "2023.3"
...
@@ -1371,6 +1402,7 @@ files = [
...
@@ -1371,6 +1402,7 @@ files = [
{file = "soundfile-0.12.1-py2.py3-none-any.whl", hash = "sha256:828a79c2e75abab5359f780c81dccd4953c45a2c4cd4f05ba3e233ddf984b882"},
{file = "soundfile-0.12.1-py2.py3-none-any.whl", hash = "sha256:828a79c2e75abab5359f780c81dccd4953c45a2c4cd4f05ba3e233ddf984b882"},
{file = "soundfile-0.12.1-py2.py3-none-macosx_10_9_x86_64.whl", hash = "sha256:d922be1563ce17a69582a352a86f28ed8c9f6a8bc951df63476ffc310c064bfa"},
{file = "soundfile-0.12.1-py2.py3-none-macosx_10_9_x86_64.whl", hash = "sha256:d922be1563ce17a69582a352a86f28ed8c9f6a8bc951df63476ffc310c064bfa"},
{file = "soundfile-0.12.1-py2.py3-none-macosx_11_0_arm64.whl", hash = "sha256:bceaab5c4febb11ea0554566784bcf4bc2e3977b53946dda2b12804b4fe524a8"},
{file = "soundfile-0.12.1-py2.py3-none-macosx_11_0_arm64.whl", hash = "sha256:bceaab5c4febb11ea0554566784bcf4bc2e3977b53946dda2b12804b4fe524a8"},
{file = "soundfile-0.12.1-py2.py3-none-manylinux_2_17_x86_64.whl", hash = "sha256:2dc3685bed7187c072a46ab4ffddd38cef7de9ae5eb05c03df2ad569cf4dacbc"},
{file = "soundfile-0.12.1-py2.py3-none-manylinux_2_31_x86_64.whl", hash = "sha256:074247b771a181859d2bc1f98b5ebf6d5153d2c397b86ee9e29ba602a8dfe2a6"},
{file = "soundfile-0.12.1-py2.py3-none-manylinux_2_31_x86_64.whl", hash = "sha256:074247b771a181859d2bc1f98b5ebf6d5153d2c397b86ee9e29ba602a8dfe2a6"},
{file = "soundfile-0.12.1-py2.py3-none-win32.whl", hash = "sha256:59dfd88c79b48f441bbf6994142a19ab1de3b9bb7c12863402c2bc621e49091a"},
{file = "soundfile-0.12.1-py2.py3-none-win32.whl", hash = "sha256:59dfd88c79b48f441bbf6994142a19ab1de3b9bb7c12863402c2bc621e49091a"},
{file = "soundfile-0.12.1-py2.py3-none-win_amd64.whl", hash = "sha256:0d86924c00b62552b650ddd28af426e3ff2d4dc2e9047dae5b3d8452e0a49a77"},
{file = "soundfile-0.12.1-py2.py3-none-win_amd64.whl", hash = "sha256:0d86924c00b62552b650ddd28af426e3ff2d4dc2e9047dae5b3d8452e0a49a77"},
...
@@ -1626,4 +1658,4 @@ socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"]
...
@@ -1626,4 +1658,4 @@ socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"]
[metadata]
[metadata]
lock-version = "2.0"
lock-version = "2.0"
python-versions = "^3.10"
python-versions = "^3.10"
content-hash = "
9b3bd7a53c5793a67b2f2cc96573d8eaf01c644bf000510d3d4e29e356f6c40
a"
content-hash = "
ca35a4cda1d1842a6fae117b5805bf43e963330173bbd66780c666b4ae903ab
a"
pyproject.toml
View file @
41fb91b4
...
@@ -14,6 +14,7 @@ pandas = "^2.0.0"
...
@@ -14,6 +14,7 @@ pandas = "^2.0.0"
scikit-learn
=
"^1.2.2"
scikit-learn
=
"^1.2.2"
grpcio-tools
=
"^1.53.0"
grpcio-tools
=
"^1.53.0"
mpai-cae-arp
=
"^0.3.0"
mpai-cae-arp
=
"^0.3.0"
python-ffmpeg
=
"^2.0.4"
[tool.poetry.group.docs.dependencies]
[tool.poetry.group.docs.dependencies]
...
...
src/segment_finder.py
View file @
41fb91b4
...
@@ -2,13 +2,15 @@ import os
...
@@ -2,13 +2,15 @@ import os
import
tempfile
import
tempfile
from
uuid
import
uuid4
from
uuid
import
uuid4
import
numpy
as
np
from
ffmpeg
import
FFmpeg
from
mpai_cae_arp.audio
import
AudioWave
,
Noise
from
mpai_cae_arp.audio
import
AudioWave
,
Noise
from
mpai_cae_arp.files
import
File
,
FileType
from
mpai_cae_arp.files
import
File
,
FileType
from
mpai_cae_arp.types.irregularity
import
Irregularity
,
IrregularityFile
,
Source
from
mpai_cae_arp.types.irregularity
import
Irregularity
,
IrregularityFile
,
Source
from
mpai_cae_arp.time
import
frames_to_seconds
,
seconds_to_frames
,
seconds_to_string
,
time_to_seconds
from
mpai_cae_arp.time
import
frames_to_seconds
,
seconds_to_frames
,
seconds_to_string
,
time_to_seconds
temp_dir
=
tempfile
.
gettempdir
()
TMP_CHANNELS_MAP
=
os
.
path
.
join
(
tempfile
.
gettempdir
(),
"mpai"
,
"channels_map.json"
)
TMP_CHANNELS_MAP
=
os
.
path
.
join
(
temp_dir
,
"channels_map.json"
)
def
calculate_offset
(
audio
:
AudioWave
,
video
:
AudioWave
)
->
float
:
def
calculate_offset
(
audio
:
AudioWave
,
video
:
AudioWave
)
->
float
:
"""
"""
...
@@ -26,12 +28,24 @@ def calculate_offset(audio: AudioWave, video: AudioWave) -> float:
...
@@ -26,12 +28,24 @@ def calculate_offset(audio: AudioWave, video: AudioWave) -> float:
float
float
"""
"""
# corr = np.correlate(audio.array, video.array, mode="full")
corr
=
np
.
correlate
(
audio
.
array
,
video
.
array
,
mode
=
"full"
)
# lags = np.arange(-len(audio.array) + 1, len(video.array))
lags
=
np
.
arange
(
-
len
(
audio
.
array
)
+
1
,
len
(
video
.
array
))
# lag_idx = np.argmax(np.abs(corr))
lag_idx
=
np
.
argmax
(
np
.
abs
(
corr
))
return
lags
[
lag_idx
]
/
audio
.
samplerate
# return lags[lag_idx] / audio.samplerate
def
get_audio_from_video
(
video_src
:
str
):
return
150
# calculate offset with ffmpeg
# ffmpeg -i video.mov -acodec pcm_s16le -ac 2 audio.wav
ffmpeg
=
(
FFmpeg
()
.
input
(
video_src
)
.
output
(
"out.wav"
,
{
""
}
)
)
def
get_irregularities_from_audio
(
audio_src
:
AudioWave
)
->
list
[
Irregularity
]:
def
get_irregularities_from_audio
(
audio_src
:
AudioWave
)
->
list
[
Irregularity
]:
...
@@ -72,6 +86,8 @@ def create_irreg_file(audio_src: str, video_src: str) -> IrregularityFile:
...
@@ -72,6 +86,8 @@ def create_irreg_file(audio_src: str, video_src: str) -> IrregularityFile:
audio
=
AudioWave
.
from_file
(
audio_src
,
bufferize
=
True
)
audio
=
AudioWave
.
from_file
(
audio_src
,
bufferize
=
True
)
offset
=
calculate_offset
(
audio
,
video_src
)
offset
=
calculate_offset
(
audio
,
video_src
)
irregularities
=
get_irregularities_from_audio
(
audio
)
irregularities
=
get_irregularities_from_audio
(
audio
)
...
...
src/server.py
View file @
41fb91b4
...
@@ -38,6 +38,10 @@ class AudioAnalyserServicer(arp_pb2_grpc.AudioAnalyserServicer):
...
@@ -38,6 +38,10 @@ class AudioAnalyserServicer(arp_pb2_grpc.AudioAnalyserServicer):
)
)
def
analyse
(
self
,
request
:
ComputationRequest
,
context
):
def
analyse
(
self
,
request
:
ComputationRequest
,
context
):
working_dir
:
str
=
request
.
working_dir
files_name
:
str
=
request
.
files_name
self
.
console
.
log
(
'Received request for computation'
)
self
.
console
.
log
(
'Received request for computation'
)
for
x
in
range
(
10
):
for
x
in
range
(
10
):
yield
ComputationResult
(
yield
ComputationResult
(
...
...
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