Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
speechrate.php
1<?php
10
16{
18 private $speedId;
19
21 private $text = '';
22
28 public static function create()
29 {
30 return new static();
31 }
32
36 public function __construct()
37 {
38 }
39
46 public function withSpeed($speedId = null)
47 {
48 $this->speedId = $speedId;
49 return $this;
50 }
51
58 public function withText($text = '')
59 {
60 $this->text = $text;
61 return $this;
62 }
63
69 public function getDuration()
70 {
71 return mb_strlen($this->text) * $this->getRatioPerChar();
72 }
73
74 private function getRatioPerChar()
75 {
76 $rates = self::getList();
77 $rate = isset($rates[$this->speedId]) ? $rates[$this->speedId] : $rates['medium'];
78
79 return self::getBaseInterval() / $rate;
80 }
81
87 public static function getList()
88 {
89 return array(
90 'x-slow' => 270,
91 'slow' => 300,
92 'medium' => 340,
93 'fast' => 370,
94 'x-fast' => 400
95 );
96 }
97
103 public static function getBaseInterval()
104 {
105 return 30;
106 }
107}