summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/modules/audio_processing/test/py_quality_assessment/apm_quality_assessment.sh
blob: aa563ee26b2527ec02d950b26443c0af1068181e (plain)
1
2
3
4
5
6
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
#!/bin/bash
# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
#
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file in the root of the source
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS.  All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.

# Path to the POLQA tool.
if [ -z ${POLQA_PATH} ]; then  # Check if defined.
  # Default location.
  export POLQA_PATH='/var/opt/PolqaOem64'
fi
if [ -d "${POLQA_PATH}" ]; then
  echo "POLQA found in ${POLQA_PATH}"
else
  echo "POLQA not found in ${POLQA_PATH}"
  exit 1
fi

# Path to the Aechen IR database.
if [ -z ${AECHEN_IR_DATABASE_PATH} ]; then  # Check if defined.
  # Default location.
  export AECHEN_IR_DATABASE_PATH='/var/opt/AIR_1_4'
fi
if [ -d "${AECHEN_IR_DATABASE_PATH}" ]; then
  echo "AIR database found in ${AECHEN_IR_DATABASE_PATH}"
else
  echo "AIR database not found in ${AECHEN_IR_DATABASE_PATH}"
  exit 1
fi

# Customize probing signals, test data generators and scores if needed.
CAPTURE_SIGNALS=(probing_signals/*.wav)
TEST_DATA_GENERATORS=( \
    "identity" \
    "white_noise" \
    # "environmental_noise" \
    # "reverberation" \
)
SCORES=( \
    # "polqa" \
    "audio_level_peak" \
    "audio_level_mean" \
)
OUTPUT_PATH=output

# Generate standard APM config files.
chmod +x apm_quality_assessment_gencfgs.py
./apm_quality_assessment_gencfgs.py

# Customize APM configurations if needed.
APM_CONFIGS=(apm_configs/*.json)

# Add output path if missing.
if [ ! -d ${OUTPUT_PATH} ]; then
  mkdir ${OUTPUT_PATH}
fi

# Start one process for each "probing signal"-"test data source" pair.
chmod +x apm_quality_assessment.py
for capture_signal_filepath in "${CAPTURE_SIGNALS[@]}" ; do
  probing_signal_name="$(basename $capture_signal_filepath)"
  probing_signal_name="${probing_signal_name%.*}"
  for test_data_gen_name in "${TEST_DATA_GENERATORS[@]}" ; do
    LOG_FILE="${OUTPUT_PATH}/apm_qa-${probing_signal_name}-"`
             `"${test_data_gen_name}.log"
    echo "Starting ${probing_signal_name} ${test_data_gen_name} "`
         `"(see ${LOG_FILE})"
    ./apm_quality_assessment.py \
        --polqa_path ${POLQA_PATH}\
        --air_db_path ${AECHEN_IR_DATABASE_PATH}\
        -i ${capture_signal_filepath} \
        -o ${OUTPUT_PATH} \
        -t ${test_data_gen_name} \
        -c "${APM_CONFIGS[@]}" \
        -e "${SCORES[@]}" > $LOG_FILE 2>&1 &
  done
done

# Join Python processes running apm_quality_assessment.py.
wait

# Export results.
chmod +x ./apm_quality_assessment_export.py
./apm_quality_assessment_export.py -o ${OUTPUT_PATH}

# Show results in the browser.
RESULTS_FILE="$(realpath ${OUTPUT_PATH}/results.html)"
sensible-browser "file://${RESULTS_FILE}" > /dev/null 2>&1 &