Repository navigation
Expand file tree
/
Copy pathVoiceLanguage.cs
More file actions
49 lines (42 loc) · 2.1 KB
/
Copy pathVoiceLanguage.cs
File metadata and controls
49 lines (42 loc) · 2.1 KB
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
// [ADDED v2026.9.24 | 2026-09-24] Purpose: One owner for the voice language.
// The display-name to culture-code mapping existed character for character in
// two files, so adding a sixth language meant editing both, and missing one
// gave speech recognition in one language with speech output in another.
using Microsoft.Maui.Storage;
namespace HO_Mind_AI
{
/// <summary>
/// The language picked in Settings, as a culture code.
///
/// It drives three separate things, and it is NOT the language of the
/// app own interface, which is English throughout:
/// - speech recognition (the SpeechToText culture)
/// - speech output (the TextToSpeech locale)
/// - the "language" field sent to /api/conversation/process
///
/// The display strings must match Picker.Items in MainPage.xaml exactly.
/// Anything unrecognised falls back to en-US rather than throwing, so a
/// renamed entry degrades to English instead of breaking the microphone.
/// </summary>
internal static class VoiceLanguage
{
private const string Key = "voice_lang";
public const string DefaultDisplayName = "English (US)";
/// <summary>The stored display name, exactly as the picker shows it.</summary>
public static string DisplayName() => Preferences.Get(Key, DefaultDisplayName) ?? DefaultDisplayName;
/// <summary>Stores the display name the picker selected.</summary>
public static void SetDisplayName(string? displayName) =>
Preferences.Set(Key, string.IsNullOrWhiteSpace(displayName) ? DefaultDisplayName : displayName);
/// <summary>The full culture code, for example "he-IL".</summary>
public static string CultureCode() => DisplayName() switch
{
"Hebrew (Israel)" => "he-IL",
"French (France)" => "fr-FR",
"Russian (Russia)" => "ru-RU",
"Arabic (SA)" => "ar-SA",
_ => "en-US",
};
/// <summary>Just the two-letter part, for example "he".</summary>
public static string LanguageCode() => CultureCode().Split('-')[0];
}
}