Created
February 18, 2025 04:05
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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