• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2024 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the 'License');
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an 'AS IS' BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""This module provides audio test data."""
15
16import os
17
18
19class AudioTestDataException(Exception):
20    """Exception for audio test data."""
21    pass
22
23
24class AudioTestData(object):
25    """Class to represent audio test data."""
26
27    def __init__(self, data_format=None, path=None, frequencies=None, duration_secs=None):
28        """Initializes an audio test file.
29
30        Args:
31            data_format: A dict containing data format including
32                         file_type, sample_format, channel, and rate.
33                         file_type: file type e.g. 'raw' or 'wav'.
34                         sample_format: One of the keys in audio_utils.SAMPLE_FORMAT.
35                         channel: number of channels.
36                         rate: sampling rate.
37            path: The path to the file.
38            frequencies: A list containing the frequency of each channel in this file.
39                         Only applicable to data of sine tone.
40            duration_secs: Duration of test file in seconds.
41
42        Raises:
43            AudioTestDataException if the path does not exist.
44        """
45        self.data_format = data_format
46        if not os.path.exists(path):
47            raise AudioTestDataException('Can not find path %s' % path)
48        self.path = path
49        self.frequencies = frequencies
50        self.duration_secs = duration_secs
51