Skip to content

Instantly share code, notes, and snippets.

@bwnyasse
Created February 18, 2025 04:05
Show Gist options
  • Save bwnyasse/f14168ad79f74d4818f6b25b8e649513 to your computer and use it in GitHub Desktop.
Save bwnyasse/f14168ad79f74d4818f6b25b8e649513 to your computer and use it in GitHub Desktop.
Building a Scrabble Companion with Gemini 2.0 : Move Explanations and Voice Synthesis
class AIService {
final LLMService _llmService;
bool _isTtsInitialized = false;
Future<String> generateMoveExplanation(
String playerName,
Move move,
int currentScore,
) async {
final prompt = '''
Explain this Scrabble move played by $playerName:
- Word: ${move.word}
- Score: ${move.score} points
- Tiles: ${move.tiles.map((t) => '${t.letter}(${t.points})').join(', ')}
- Current total: $currentScore points
Keep it brief but informative in 2 sentences maximum.
''';
return await _llmService.generateExplanation(prompt);
}
Future<List<int>> convertToSpeech(String text, AppLanguage language) async {
if (!_isTtsInitialized) {
await _initializeTts();
}
final targetVoice = language == AppLanguage.english
? 'en-US-Wavenet-I' // English male voice
: 'fr-FR-Wavenet-D'; // French male voice
final params = TtsParamsGoogle(
voice: voice,
audioFormat: AudioOutputFormatGoogle.linear16,
text: text,
);
final ttsResponse = await TtsGoogle.convertTts(params);
return ttsResponse.audio.buffer.asUint8List().toList();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment