PluginProbe
BeyondWords – AI audio for publishers / 6.3.0
BeyondWords – AI audio for publishers v6.3.0
7.1.0 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.7.0 All 43 releases
speechkit / src / Component / Settings / Fields / Voice / Voice.php

Voice.php in BeyondWords – AI audio for publishers 6.3.0, at src/Component/Settings/Fields/Voice/Voice.php

61 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 /**
6 * Setting: Voice
7 *
8 * @package Beyondwords\Wordpress
9 * @author Stuart McAlpine <stu@beyondwords.io>
10 * @since 5.0.0
11 */
12
13 namespace Beyondwords\Wordpress\Component\Settings\Fields\Voice;
14
15 use Beyondwords\Wordpress\Core\ApiClient;
16
17 defined('ABSPATH') || exit;
18
19 /**
20 * Voice
21 *
22 * @since 5.0.0
23 */
24 abstract class Voice
25 {
26 /**
27 * Get all options for the current component.
28 *
29 * @since 5.0.0
30 * @since 5.4.0
31 * @since 6.0.0 Make static, handle API errors, and return language_code in each option.
32 *
33 * @return string[] Associative array of options.
34 **/
35 public static function getOptions()
36 {
37 $voices = null;
38 $languageCode = get_option('beyondwords_project_language_code');
39 if ($languageCode) {
40 $voices = ApiClient::getVoices($languageCode);
41 }
42
43 if (! $voices || ! is_array($voices) || empty($voices)) {
44 return [];
45 }
46
47 // Filter out any non-array elements (in case of API errors)
48 $voices = array_filter($voices, 'is_array');
49
50 if (empty($voices)) {
51 return [];
52 }
53
54 return array_map(fn($voice) => [
55 'value' => $voice['id'],
56 'label' => $voice['name'],
57 'language_code' => $voice['language']['code'] ?? '',
58 ], $voices);
59 }
60 }
61