TtsAudioFormat::getFileExtension()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace GinoPane\PHPolyglot\API\Supplemental\TTS;
4
5
use GinoPane\PHPolyglot\Supplemental\GetConstantsTrait;
6
7
/**
8
 * Interface TtsAudioFormats
9
 *
10
 * The interface provides constants for popular basic audio formats. They are completely optional, you can use
11
 * every other identifier for audio format, just be sure that your chosen API supports that key and can correctly
12
 * process it
13
 *
14
 * @author Sergey <Gino Pane> Karavay
15
 */
16
class TtsAudioFormat
17
{
18
    const AUDIO_BASIC       = 'basic';
19
    const AUDIO_FLAC        = 'flac';
20
    const AUDIO_L16         = 'l16';
21
    const AUDIO_MP3         = 'mp3';
22
    const AUDIO_MPEG        = 'mpeg';
23
    const AUDIO_MULAW       = 'mulaw';
24
    const AUDIO_OGG         = 'ogg';
25
    const AUDIO_WAV         = 'wav';
26
    const AUDIO_WEBM        = 'webm';
27
28
    /**
29
     * @link https://console.bluemix.net/docs/services/speech-to-text/audio-formats.html
30
     *
31
     * @var string[]
32
     */
33
    private static $defaultFileExtensions = [
34
        self::AUDIO_BASIC       => 'au',
35
        self::AUDIO_FLAC        => 'flac',
36
        self::AUDIO_L16         => 'l16',
37
        self::AUDIO_MP3         => 'mp3',
38
        self::AUDIO_MPEG        => 'mp3',
39
        self::AUDIO_MULAW       => 'ulaw',
40
        self::AUDIO_OGG         => 'ogg',
41
        self::AUDIO_WAV         => 'wav',
42
        self::AUDIO_WEBM        => 'webm'
43
    ];
44
45
    /**
46
     * Stored audio format. Set to mp3 format by default
47
     *
48
     * @var string
49
     */
50
    private $format = self::AUDIO_MP3;
51
52
    use GetConstantsTrait;
53
54
    /**
55
     * TtsAudioFormat constructor
56
     *
57
     * @param string $format
58
     */
59
    public function __construct(string $format = self::AUDIO_MP3)
60
    {
61
        $format = strtolower($format);
62
63
        if ($this->constantValueExists($format)) {
64
            $this->format = $format;
65
        } else {
66
            $this->format = self::AUDIO_MP3;
67
        }
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getFormat(): string
74
    {
75
        return $this->format;
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    public function getFileExtension(): string
82
    {
83
        return self::$defaultFileExtensions[$this->format];
84
    }
85
}
86