Skip to content

Commit

Permalink
Minor refactoring, voices + default voice now common constants + comp…
Browse files Browse the repository at this point in the history
…at. fix f. old prefs
  • Loading branch information
sveinbjornt committed May 31, 2022
1 parent f34bfdb commit 70f2a12
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
5 changes: 4 additions & 1 deletion lib/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ const String kQueryHistoryAPIPath = '/query_history.api/v1';
const String kSpeechSynthesisAPIPath = '/speech.api/v1';
const String kVoiceListAPIPath = '/voices.api/v1';

// Voice speed range
// Speech synthesis
const List kSpeechSynthesisVoices = ["Dóra", "Karl"];
const String kDefaultVoice = "Dóra";

const double kVoiceSpeedMin = 0.7;
const double kVoiceSpeedMax = 2.0;

Expand Down
6 changes: 6 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ void main() async {
if (Prefs().stringForKey("voice_id") == "Kona") {
Prefs().setStringForKey("voice_id", "Dóra");
}
// Hack mapping "Dora" to "Dóra" in Prefs. This is purely for cosmetic
// reasons, as the voice name is displayed in the UI.
if (Prefs().stringForKey("voice_id") == "Dora") {
Prefs().setStringForKey("voice_id", "Dóra");
}

dlog("Shared prefs: ${Prefs().desc()}");

// Init/preload these to prevent any lag after launching app
Expand Down
15 changes: 5 additions & 10 deletions lib/voices.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,14 @@ import 'package:flutter/foundation.dart' show kReleaseMode;

import './prefs.dart' show Prefs;
import './query.dart' show QueryService;
import './common.dart' show dlog;
import './common.dart' show dlog, kSpeechSynthesisVoices, kDefaultVoice;
import './theme.dart';

// Fallback voices and default voice if offline
// and unable to query server for voices list
const List _fallbackVoices = ["Dóra", "Karl"];
const String _fallbackDefaultVoice = "Dóra";

List voices;

Future<List> fetchVoiceList() async {
if (kReleaseMode) {
voices = _fallbackVoices;
voices = kSpeechSynthesisVoices;
}

if (voices != null) {
Expand All @@ -44,8 +39,8 @@ Future<List> fetchVoiceList() async {

try {
Map res = await QueryService.requestSupportedVoices();
List voiceList = _fallbackVoices;
String defaultVoice = _fallbackDefaultVoice;
List voiceList = kSpeechSynthesisVoices;
String defaultVoice = kDefaultVoice;

if (res != null && res.containsKey("valid") == true && res["valid"] == true) {
// We have a valid response from the server
Expand All @@ -68,7 +63,7 @@ Future<List> fetchVoiceList() async {
voices = voiceList;
} catch (e) {
dlog("Error fetching voice list: $e");
voices = _fallbackVoices;
voices = kSpeechSynthesisVoices;
}

return voices;
Expand Down

0 comments on commit 70f2a12

Please sign in to comment.