Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
TMP-23-310
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TMP-23-310
TMP-23-310
Commits
0d881870
Commit
0d881870
authored
Oct 31, 2023
by
IT20146474 Liyanage A.L.D.K.S
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new
parent
4af96531
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1169 additions
and
0 deletions
+1169
-0
lib/fun_spelling_screen.dart
lib/fun_spelling_screen.dart
+291
-0
lib/main.dart
lib/main.dart
+140
-0
lib/similar_words_screen.dart
lib/similar_words_screen.dart
+216
-0
lib/sounds_of_animals_screen.dart
lib/sounds_of_animals_screen.dart
+230
-0
lib/synonyms.dart
lib/synonyms.dart
+20
-0
lib/word_pronunciation.dart
lib/word_pronunciation.dart
+272
-0
No files found.
lib/fun_spelling_screen.dart
0 → 100644
View file @
0d881870
import
'dart:math'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_tts/flutter_tts.dart'
;
import
'package:speech_to_text/speech_to_text.dart'
as
stt
;
void
main
(
)
{
runApp
(
MyApp
());
}
class
MyApp
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
home:
SpellingGame
(),
);
}
}
class
SpellingGame
extends
StatefulWidget
{
@override
_SpellingGameState
createState
()
=>
_SpellingGameState
();
}
class
_SpellingGameState
extends
State
<
SpellingGame
>
{
final
FlutterTts
flutterTts
=
FlutterTts
();
final
stt
.
SpeechToText
speech
=
stt
.
SpeechToText
();
String
currentWord
=
"sky"
;
String
?
userSpelling
;
String
?
message
;
List
<
String
>
easyWords
=
[
"sky"
,
"cat"
,
"dog"
,
"hat"
];
List
<
String
>
mediumWords
=
[
"banana"
,
"guitar"
,
"table"
,
"orange"
];
List
<
String
>
hardWords
=
[
"elephant"
,
"chocolate"
,
"technology"
,
"paradise"
];
String
?
selectedLevel
=
'easy'
;
// Default level
int
correctCount
=
0
;
int
incorrectCount
=
0
;
bool
shouldValidateSpelling
=
false
;
// Flag to control validation
List
<
String
>
spelledLetters
=
[];
// List to hold the spelled letters
@override
void
initState
()
{
super
.
initState
();
_playWord
();
_speak
(
"Welcome to the Spelling Game! Please spell the word that you hear. Double tap to hear the word. Swipe left to speak a synonym."
);
_listenForVoiceCommands
();
// Start listening for voice commands
}
_speak
(
String
text
)
async
{
await
flutterTts
.
speak
(
text
);
}
_listenForSpelling
()
async
{
bool
available
=
await
speech
.
initialize
(
onStatus:
(
val
)
=>
print
(
'onStatus:
$val
'
),
);
if
(
available
)
{
speech
.
listen
(
onResult:
(
val
)
=>
setState
(()
{
userSpelling
=
val
.
recognizedWords
;
spelledLetters
=
userSpelling
?.
split
(
''
)
??
[];
}),
onSoundLevelChange:
(
val
)
{
if
(
val
>
500
&&
shouldValidateSpelling
)
{
_validateSpelling
();
}
},
cancelOnError:
true
,
);
}
}
_validateSpelling
()
{
shouldValidateSpelling
=
false
;
// Reset the flag
String
spelledWord
=
spelledLetters
.
join
(
''
).
toLowerCase
();
if
(
spelledWord
==
currentWord
||
spelledLetters
.
join
(
''
)
==
currentWord
)
{
setState
(()
{
message
=
"Correct! You spelled it correctly."
;
correctCount
++;
});
_speak
(
"Correct! You spelled it correctly."
);
}
else
{
setState
(()
{
message
=
"Try again! Your spelling is incorrect."
;
incorrectCount
++;
});
_speak
(
"Try again! Your spelling is incorrect."
);
}
// Clear the user spelling after validation
userSpelling
=
null
;
spelledLetters
=
[];
}
_playWord
()
{
setState
(()
{
userSpelling
=
null
;
message
=
null
;
shouldValidateSpelling
=
true
;
// Set the flag for validation
spelledLetters
=
[];
// Clear the spelled letters
});
List
<
String
>
selectedWordList
=
easyWords
;
if
(
selectedLevel
==
'medium'
)
{
selectedWordList
=
mediumWords
;
}
else
if
(
selectedLevel
==
'hard'
)
{
selectedWordList
=
hardWords
;
}
final
random
=
Random
();
currentWord
=
selectedWordList
[
random
.
nextInt
(
selectedWordList
.
length
)];
_speak
(
"Spell the word:"
);
_speak
(
currentWord
);
}
_listenForVoiceCommands
()
async
{
bool
available
=
await
speech
.
initialize
(
onStatus:
(
val
)
=>
print
(
'onStatus:
$val
'
),
);
if
(
available
)
{
speech
.
listen
(
onResult:
(
val
)
{
String
command
=
val
.
recognizedWords
.
toLowerCase
();
if
(
command
.
contains
(
"easy"
))
{
_changeDifficultyLevel
(
'easy'
);
}
else
if
(
command
.
contains
(
"medium"
))
{
_changeDifficultyLevel
(
'medium'
);
}
else
if
(
command
.
contains
(
"hard"
))
{
_changeDifficultyLevel
(
'hard'
);
}
},
);
}
}
void
_changeDifficultyLevel
(
String
level
)
{
setState
(()
{
selectedLevel
=
level
;
});
_playWord
();
_speak
(
"Level changed to
$level
"
);
}
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
'Spelling Game'
),
backgroundColor:
const
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
),
body:
GestureDetector
(
onTap:
_playWord
,
onDoubleTap:
()
{
print
(
'Double Tapped!'
);
_playWord
();
},
onHorizontalDragEnd:
(
details
)
{
if
(
details
.
primaryVelocity
!.
compareTo
(
0
)
==
-
1
)
{
_listenForSpelling
();
}
else
if
(
details
.
primaryVelocity
!.
compareTo
(
0
)
==
1
)
{
_playWord
();
}
},
child:
Container
(
color:
Colors
.
lightBlue
[
100
],
child:
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
crossAxisAlignment:
CrossAxisAlignment
.
center
,
children:
[
Image
.
asset
(
'assets/images/bee.png'
,
// image
width:
500
,
height:
250
,
),
const
SizedBox
(
height:
20
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
ElevatedButton
(
onPressed:
()
{
_changeDifficultyLevel
(
'easy'
);
},
child:
Text
(
"Easy"
),
style:
ElevatedButton
.
styleFrom
(
primary:
const
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
// Custom color
),
),
SizedBox
(
width:
20
),
ElevatedButton
(
onPressed:
()
{
_changeDifficultyLevel
(
'medium'
);
},
child:
Text
(
"Medium"
),
style:
ElevatedButton
.
styleFrom
(
primary:
const
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
// Custom color
),
),
SizedBox
(
width:
20
),
ElevatedButton
(
onPressed:
()
{
_changeDifficultyLevel
(
'hard'
);
},
child:
Text
(
"Hard"
),
style:
ElevatedButton
.
styleFrom
(
primary:
const
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
// Custom color
),
),
],
),
const
SizedBox
(
height:
20
),
Container
(
width:
200
,
height:
60
,
child:
ElevatedButton
(
onPressed:
_playWord
,
child:
const
Text
(
"Play Word"
,
style:
TextStyle
(
fontSize:
20
),
),
style:
ElevatedButton
.
styleFrom
(
primary:
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
// Custom color
),
),
),
const
SizedBox
(
height:
20
),
Container
(
width:
200
,
height:
60
,
child:
ElevatedButton
(
onPressed:
_listenForSpelling
,
child:
const
Text
(
"Speak Spelling"
,
style:
TextStyle
(
fontSize:
20
),
),
style:
ElevatedButton
.
styleFrom
(
primary:
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
// Custom color
),
),
),
const
SizedBox
(
height:
20
),
Container
(
width:
200
,
height:
60
,
child:
ElevatedButton
(
onPressed:
_validateSpelling
,
child:
const
Text
(
"Confirm Spelling"
,
style:
TextStyle
(
fontSize:
20
),
),
style:
ElevatedButton
.
styleFrom
(
primary:
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
// Custom color
),
),
),
const
SizedBox
(
height:
20
),
Text
(
"Your Spelling:
${spelledLetters.join('')}
"
,
style:
const
TextStyle
(
fontSize:
25
),
),
Text
(
message
??
''
,
style:
const
TextStyle
(
fontSize:
25
),
),
],
),
),
),
),
bottomNavigationBar:
BottomAppBar
(
child:
Container
(
height:
50
,
child:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
Text
(
'Correct:
$correctCount
'
),
SizedBox
(
width:
20
),
Text
(
'Incorrect:
$incorrectCount
'
),
],
),
),
),
);
}
}
lib/main.dart
0 → 100644
View file @
0d881870
import
'package:flutter/material.dart'
;
import
'sounds_of_animals_screen.dart'
;
import
'fun_spelling_screen.dart'
;
import
'similar_words_screen.dart'
;
import
'package:flutter_tts/flutter_tts.dart'
;
void
main
(
)
{
runApp
(
MyApp
());
speak
(
'Welcome to the Edu Sense Games !.'
'To play the Sound of animal game , tap the top of the screen.'
'To play the fun spelling game , tap the middle of the screen.'
'To play the Synonyms Word game , tap the bottom of the screen.'
);
}
Future
<
void
>
speak
(
String
text
)
async
{
FlutterTts
flutterTts
=
FlutterTts
();
await
flutterTts
.
setLanguage
(
'en-US'
);
// Set the language
await
flutterTts
.
setSpeechRate
(
0.5
);
// Adjust the speech rate
await
flutterTts
.
speak
(
text
);
}
class
MyApp
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
home:
HomeScreen
(),
debugShowCheckedModeBanner:
false
,
);
}
}
class
HomeScreen
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
'Edu Sense Games'
),
backgroundColor:
const
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
),
body:
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
CustomButton
(
text:
'Sounds of Animals'
,
imagePath:
'assets/images/a.png'
,
imageHeight:
135
,
imageWidth:
135
,
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
GameScreen
()),
);
},
),
SizedBox
(
height:
20
),
CustomButton
(
text:
'Fun Spelling'
,
imagePath:
'assets/images/b.png'
,
imageHeight:
135
,
imageWidth:
135
,
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
SpellingGame
()),
);
},
),
SizedBox
(
height:
20
),
CustomButton
(
text:
'Synonyms Words'
,
imagePath:
'assets/images/c.png'
,
imageHeight:
135
,
imageWidth:
135
,
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
SynonymsGame
()),
);
},
),
],
),
),
);
}
}
class
CustomButton
extends
StatelessWidget
{
final
String
text
;
final
VoidCallback
onPressed
;
final
String
imagePath
;
final
double
imageHeight
;
final
double
imageWidth
;
CustomButton
({
required
this
.
text
,
required
this
.
onPressed
,
required
this
.
imagePath
,
this
.
imageHeight
=
80.0
,
// Default image height
this
.
imageWidth
=
80.0
,
// Default image width
});
@override
Widget
build
(
BuildContext
context
)
{
return
ElevatedButton
(
onPressed:
onPressed
,
style:
ElevatedButton
.
styleFrom
(
padding:
EdgeInsets
.
all
(
0
),
minimumSize:
Size
(
360
,
200
),
// Adjust the width and height
shape:
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
circular
(
20
),
// Adjust the radius
),
backgroundColor:
Color
.
fromARGB
(
255
,
13
,
128
,
222
),
// Set the button color here
),
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
Image
.
asset
(
imagePath
,
height:
imageHeight
,
width:
imageWidth
,
),
SizedBox
(
height:
8.0
),
Text
(
text
,
textAlign:
TextAlign
.
center
,
style:
TextStyle
(
fontSize:
45
,
// Adjust the font size
color:
Colors
.
white
,
// Set the text color
),
),
],
),
);
}
}
lib/similar_words_screen.dart
0 → 100644
View file @
0d881870
import
'dart:async'
;
import
'dart:math'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_tts/flutter_tts.dart'
;
import
'package:speech_to_text/speech_to_text.dart'
as
stt
;
import
'synonyms.dart'
;
// Import the synonyms.dart file
void
main
(
)
{
runApp
(
MyApp
());
}
class
MyApp
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
home:
SynonymsGame
(),
);
}
}
class
SynonymsGame
extends
StatefulWidget
{
@override
_SynonymsGameState
createState
()
=>
_SynonymsGameState
();
}
class
_SynonymsGameState
extends
State
<
SynonymsGame
>
{
final
FlutterTts
flutterTts
=
FlutterTts
();
final
stt
.
SpeechToText
speech
=
stt
.
SpeechToText
();
bool
isListening
=
false
;
String
word
=
"happy"
;
String
?
spokenWord
;
String
?
message
;
Timer
?
feedbackDebounce
;
Timer
?
tripleTapTimer
;
int
tapCount
=
0
;
final
Random
random
=
Random
();
int
correctAnswers
=
0
;
int
totalAnswers
=
0
;
@override
void
initState
()
{
super
.
initState
();
_nextWord
();
_speak
(
"Welcome to the Synonyms Game! Double tap to hear the word. Swipe left to speak a synonym."
);
}
_speak
(
String
text
)
async
{
await
flutterTts
.
speak
(
text
);
}
_listen
()
async
{
bool
available
=
await
speech
.
initialize
(
onStatus:
(
val
)
=>
print
(
'onStatus:
$val
'
),
);
if
(
available
)
{
setState
(()
=>
isListening
=
true
);
speech
.
listen
(
onResult:
(
val
)
=>
setState
(()
{
spokenWord
=
val
.
recognizedWords
;
isListening
=
false
;
_validateAnswer
();
}),
);
}
}
_validateAnswer
()
{
if
(
spokenWord
!=
null
&&
wordSynonyms
[
word
]!.
contains
(
spokenWord
))
{
setState
(()
{
message
=
"Correct!"
;
correctAnswers
++;
totalAnswers
++;
});
_giveFeedback
(
"Correct! Great job!"
);
_nextWord
();
}
else
{
setState
(()
{
message
=
"Try again!"
;
totalAnswers
++;
});
_giveFeedback
(
"You are incorrect. Try again!"
);
}
speech
.
stop
();
// Stop listening after validating
}
_giveFeedback
(
String
feedback
)
{
feedbackDebounce
?.
cancel
();
feedbackDebounce
=
Timer
(
const
Duration
(
milliseconds:
600
),
()
{
speech
.
stop
();
// Ensure that the app is not listening when it speaks
_speak
(
feedback
);
});
}
_nextWord
()
{
final
keys
=
wordSynonyms
.
keys
.
toList
();
word
=
keys
[
random
.
nextInt
(
keys
.
length
)];
}
_handleTap
()
{
tapCount
++;
tripleTapTimer
?.
cancel
();
tripleTapTimer
=
Timer
(
const
Duration
(
milliseconds:
500
),
()
{
if
(
tapCount
==
3
)
{
_nextWord
();
_speak
(
word
);
// Play the next word
}
tapCount
=
0
;
});
}
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
'Synonyms Game'
),
backgroundColor:
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
),
body:
GestureDetector
(
onTap:
_handleTap
,
onDoubleTap:
()
{
print
(
'Double Tapped!'
);
_speak
(
word
);
},
onHorizontalDragEnd:
(
details
)
{
if
(
details
.
primaryVelocity
!.
compareTo
(
0
)
==
-
1
)
{
_listen
();
}
else
if
(
details
.
primaryVelocity
!.
compareTo
(
0
)
==
1
)
{
_speak
(
word
);
}
},
child:
Container
(
color:
Colors
.
lightBlue
[
100
],
child:
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
crossAxisAlignment:
CrossAxisAlignment
.
center
,
children:
[
Image
.
asset
(
'assets/images/book.png'
,
// Replace with your image
width:
500
,
height:
180
,
),
const
SizedBox
(
height:
20
),
Container
(
width:
200
,
height:
60
,
child:
ElevatedButton
(
onPressed:
()
=>
_speak
(
word
),
child:
const
Text
(
"Play Word"
,
style:
TextStyle
(
fontSize:
20
),
),
style:
ButtonStyle
(
backgroundColor:
MaterialStateProperty
.
all
<
Color
>(
Color
.
fromARGB
(
255
,
39
,
20
,
204
)),
),
),
),
const
SizedBox
(
height:
20
),
Container
(
width:
200
,
height:
60
,
child:
ElevatedButton
(
onPressed:
_listen
,
child:
const
Text
(
"Speak Synonym"
,
style:
TextStyle
(
fontSize:
20
),
),
style:
ButtonStyle
(
backgroundColor:
MaterialStateProperty
.
all
<
Color
>(
Color
.
fromARGB
(
255
,
39
,
20
,
204
)),
),
),
),
const
SizedBox
(
height:
20
),
Container
(
width:
200
,
height:
60
,
child:
ElevatedButton
(
onPressed:
()
{
_nextWord
();
_speak
(
word
);
// Play the next word
},
child:
const
Text
(
"Next Word"
,
style:
TextStyle
(
fontSize:
18
),
),
style:
ButtonStyle
(
backgroundColor:
MaterialStateProperty
.
all
<
Color
>(
const
Color
.
fromARGB
(
255
,
39
,
20
,
204
)),
),
),
),
const
SizedBox
(
height:
20
),
Text
(
"You Answer:
${spokenWord ?? ''}
"
,
style:
const
TextStyle
(
fontSize:
35
),
),
Text
(
message
??
''
,
style:
const
TextStyle
(
fontSize:
35
),
),
Text
(
"Correct Answers:
$correctAnswers
"
,
style:
const
TextStyle
(
fontSize:
20
),
),
],
),
),
),
),
);
}
}
lib/sounds_of_animals_screen.dart
0 → 100644
View file @
0d881870
import
'package:flutter/material.dart'
;
import
'package:audioplayers/audioplayers.dart'
;
import
'package:speech_to_text/speech_to_text.dart'
as
stt
;
import
'package:flutter_tts/flutter_tts.dart'
;
void
main
(
)
{
runApp
(
MyApp
());
}
class
MyApp
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
home:
GameScreen
(),
);
}
}
class
GameScreen
extends
StatefulWidget
{
@override
_GameScreenState
createState
()
=>
_GameScreenState
();
}
class
_GameScreenState
extends
State
<
GameScreen
>
{
final
AudioPlayer
_audioPlayer
=
AudioPlayer
();
TextEditingController
guessController
=
TextEditingController
();
stt
.
SpeechToText
_speechToText
=
stt
.
SpeechToText
();
FlutterTts
flutterTts
=
FlutterTts
();
List
<
String
>
animalSounds
=
[
'lion.mp3'
,
'cat.mp3'
,
'dog.mp3'
,
'cow.mp3'
,
'frog.mp3'
,
'peacock.mp3'
,
'horse.mp3'
,
'elephant.mp3'
,
'duck.mp3'
'bird.mp3'
'owl.mp3'
'elk.mp3'
'Sheep.mp3'
'Chicken.mp3'
];
// sound files
List
<
String
>
animalNames
=
[
'lion'
,
'cat'
,
'dog'
,
'cow'
,
'frog'
,
'peacock'
,
'horse'
,
'elephant'
,
'duck'
'bird'
'owl'
'elk'
'sheep'
'chicken'
];
// animal names
int
currentAnimalIndex
=
0
;
@override
void
initState
()
{
super
.
initState
();
playSound
();
speak
(
'Welcome to the Animal Sound Game! Listen to the animal sound and guess the animal.. Double tap to hear the Animal sound. Swipe left to Answer.'
);
}
void
playSound
()
async
{
await
_audioPlayer
.
play
(
AssetSource
(
'audio/
${animalSounds[currentAnimalIndex]}
'
));
}
void
checkGuess
()
{
String
userGuess
=
guessController
.
text
.
toLowerCase
();
String
correctAnimal
=
animalNames
[
currentAnimalIndex
];
if
(
userGuess
==
correctAnimal
)
{
speak
(
'Correct! Your guess is right. Well done!'
);
showDialog
(
context:
context
,
builder:
(
_
)
=>
AlertDialog
(
title:
Text
(
'Correct!'
),
content:
Text
(
'Your guess is correct.'
),
actions:
[
TextButton
(
onPressed:
()
{
Navigator
.
pop
(
context
);
moveToNextAnimal
();
},
child:
Text
(
'Next Animal'
),
),
],
),
);
}
else
{
speak
(
'Incorrect. Your guess is incorrect. Try again.'
);
showDialog
(
context:
context
,
builder:
(
_
)
=>
AlertDialog
(
title:
Text
(
'Incorrect'
),
content:
Text
(
'Your guess is incorrect. Try again.'
),
actions:
[
TextButton
(
onPressed:
()
{
Navigator
.
pop
(
context
);
},
child:
Text
(
'OK'
),
),
],
),
);
}
}
void
moveToNextAnimal
()
{
if
(
currentAnimalIndex
<
animalSounds
.
length
-
1
)
{
setState
(()
{
currentAnimalIndex
++;
});
playSound
();
speak
(
'Listen to the next animal sound and make your guess.'
);
}
else
{
speak
(
'Congratulations! You have finished the game.'
);
}
}
void
speak
(
String
text
)
async
{
await
flutterTts
.
speak
(
text
);
}
void
startListening
()
async
{
if
(
await
_speechToText
.
initialize
())
{
_speechToText
.
listen
(
onResult:
(
result
)
{
if
(
result
.
finalResult
)
{
guessController
.
text
=
result
.
recognizedWords
.
toLowerCase
();
_speechToText
.
stop
();
checkGuess
();
}
},
);
}
}
@override
void
dispose
()
{
_speechToText
.
stop
();
super
.
dispose
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
'Animal Sound Game'
),
backgroundColor:
const
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
),
body:
Stack
(
children:
[
GestureDetector
(
onDoubleTap:
playSound
,
onHorizontalDragEnd:
(
details
)
{
if
(
details
.
primaryVelocity
!
<
0
)
{
startListening
();
}
},
child:
Container
(
color:
Colors
.
lightBlue
[
100
],
width:
double
.
infinity
,
height:
double
.
infinity
,
),
),
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
Image
.
asset
(
'assets/images/animals.png'
,
// image file name
width:
300
,
height:
300
,
),
ElevatedButton
(
onPressed:
playSound
,
style:
ElevatedButton
.
styleFrom
(
backgroundColor:
const
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
),
child:
Text
(
'Play Sound'
),
),
SizedBox
(
height:
20
),
Container
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
20
),
child:
TextField
(
controller:
guessController
,
decoration:
InputDecoration
(
labelText:
'Your Answer'
,
),
maxLines:
1
,
),
),
SizedBox
(
height:
10
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
ElevatedButton
(
onPressed:
checkGuess
,
style:
ElevatedButton
.
styleFrom
(
backgroundColor:
const
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
),
child:
Text
(
'Check'
),
),
SizedBox
(
width:
20
),
ElevatedButton
(
onPressed:
startListening
,
style:
ElevatedButton
.
styleFrom
(
backgroundColor:
const
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
),
child:
Text
(
'Voice Input'
),
),
],
),
],
),
),
],
),
);
}
}
lib/synonyms.dart
0 → 100644
View file @
0d881870
// synonyms.dart
final
Map
<
String
,
List
<
String
>>
wordSynonyms
=
{
"happy"
:
[
"joyful"
,
"pleased"
,
"glad"
],
"sad"
:
[
"unhappy"
,
"mournful"
,
"downcast"
],
"angry"
:
[
"irate"
,
"mad"
,
"furious"
],
"calm"
:
[
"serene"
,
"peaceful"
,
"composed"
],
"bright"
:
[
"radiant"
,
"shiny"
,
"luminous"
],
"dark"
:
[
"gloomy"
,
"shadowy"
,
"dim"
],
"fast"
:
[
"quick"
,
"swift"
,
"speedy"
],
"slow"
:
[
"lethargic"
,
"sluggish"
,
"lazy"
],
"big"
:
[
"large"
,
"huge"
,
"massive"
],
"small"
:
[
"tiny"
,
"miniature"
,
"compact"
],
"smart"
:
[
"intelligent"
,
"clever"
,
"bright"
],
"dumb"
:
[
"stupid"
,
"dull"
,
"dense"
],
"easy"
:
[
"simple"
,
"effortless"
,
"straightforward"
],
"hard"
:
[
"difficult"
,
"tough"
,
"challenging"
],
"strong"
:
[
"sturdy"
,
"robust"
,
"resilient"
],
"weak"
:
[
"fragile"
,
"feeble"
,
"delicate"
]
};
lib/word_pronunciation.dart
0 → 100644
View file @
0d881870
import
'dart:math'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_tts/flutter_tts.dart'
;
import
'package:speech_to_text/speech_to_text.dart'
as
stt
;
void
main
(
)
{
runApp
(
MyApp
());
}
class
MyApp
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
home:
PronunciationGame
(),
);
}
}
class
PronunciationGame
extends
StatefulWidget
{
@override
_PronunciationGameState
createState
()
=>
_PronunciationGameState
();
}
class
_PronunciationGameState
extends
State
<
PronunciationGame
>
{
final
FlutterTts
flutterTts
=
FlutterTts
();
final
stt
.
SpeechToText
speech
=
stt
.
SpeechToText
();
String
currentWord
=
"sky"
;
String
?
userPronunciation
;
String
?
message
;
List
<
String
>
easyWords
=
[
"sky"
,
"cat"
,
"dog"
,
"hat"
];
List
<
String
>
mediumWords
=
[
"banana"
,
"guitar"
,
"table"
,
"orange"
];
List
<
String
>
hardWords
=
[
"elephant"
,
"chocolate"
,
"technology"
,
"paradise"
];
String
?
selectedLevel
=
'easy'
;
// Default level
int
correctCount
=
0
;
int
incorrectCount
=
0
;
bool
shouldValidatePronunciation
=
false
;
// Flag to control validation
@override
void
initState
()
{
super
.
initState
();
_pronounceWord
();
_speak
(
"Welcome to the Pronunciation Game! Please pronounce the word that you hear. Double tap to hear the word."
);
_listenForVoiceCommands
();
// Start listening for voice commands
}
_speak
(
String
text
)
async
{
await
flutterTts
.
speak
(
text
);
}
_listenForPronunciation
()
async
{
bool
available
=
await
speech
.
initialize
(
onStatus:
(
val
)
=>
print
(
'onStatus:
$val
'
),
);
if
(
available
)
{
speech
.
listen
(
onResult:
(
val
)
=>
setState
(()
{
userPronunciation
=
val
.
recognizedWords
;
}),
onSoundLevelChange:
(
val
)
{
if
(
val
>
500
&&
shouldValidatePronunciation
)
{
_validatePronunciation
();
}
},
cancelOnError:
true
,
);
}
}
_validatePronunciation
()
{
shouldValidatePronunciation
=
false
;
// Reset the flag
String
pronouncedWord
=
userPronunciation
?.
toLowerCase
()
??
""
;
String
currentWordLower
=
currentWord
.
toLowerCase
();
if
(
pronouncedWord
==
currentWordLower
)
{
setState
(()
{
message
=
"Correct! You pronounced it correctly."
;
correctCount
++;
});
_speak
(
"Correct! You pronounced it correctly."
);
}
else
{
setState
(()
{
message
=
"Try again! Your pronunciation is incorrect."
;
incorrectCount
++;
});
_speak
(
"Try again! Your pronunciation is incorrect."
);
}
}
_pronounceWord
()
{
setState
(()
{
userPronunciation
=
null
;
message
=
null
;
shouldValidatePronunciation
=
true
;
// Set the flag for validation
});
List
<
String
>
selectedWordList
=
easyWords
;
if
(
selectedLevel
==
'medium'
)
{
selectedWordList
=
mediumWords
;
}
else
if
(
selectedLevel
==
'hard'
)
{
selectedWordList
=
hardWords
;
}
final
random
=
Random
();
currentWord
=
selectedWordList
[
random
.
nextInt
(
selectedWordList
.
length
)];
_speak
(
"Pronounce the word:"
);
_speak
(
currentWord
);
}
_listenForVoiceCommands
()
async
{
bool
available
=
await
speech
.
initialize
(
onStatus:
(
val
)
=>
print
(
'onStatus:
$val
'
),
);
if
(
available
)
{
speech
.
listen
(
onResult:
(
val
)
{
String
command
=
val
.
recognizedWords
.
toLowerCase
();
if
(
command
.
contains
(
"easy"
))
{
_changeDifficultyLevel
(
'easy'
);
}
else
if
(
command
.
contains
(
"medium"
))
{
_changeDifficultyLevel
(
'medium'
);
}
else
if
(
command
.
contains
(
"hard"
))
{
_changeDifficultyLevel
(
'hard'
);
}
},
);
}
}
void
_changeDifficultyLevel
(
String
level
)
{
setState
(()
{
selectedLevel
=
level
;
});
_pronounceWord
();
_speak
(
"Level changed to
$level
"
);
}
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
'Pronunciation Game'
),
backgroundColor:
const
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
),
body:
GestureDetector
(
onTap:
_pronounceWord
,
onDoubleTap:
()
{
print
(
'Double Tapped!'
);
_pronounceWord
();
},
onHorizontalDragEnd:
(
details
)
{
if
(
details
.
primaryVelocity
!.
compareTo
(
0
)
==
-
1
)
{
_listenForPronunciation
();
}
else
if
(
details
.
primaryVelocity
!.
compareTo
(
0
)
==
1
)
{
_pronounceWord
();
}
},
child:
Container
(
color:
Colors
.
lightBlue
[
100
],
child:
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
crossAxisAlignment:
CrossAxisAlignment
.
center
,
children:
[
Image
.
asset
(
'assets/images/bee.png'
,
// Replace with your image
width:
500
,
height:
250
,
),
const
SizedBox
(
height:
20
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
ElevatedButton
(
onPressed:
()
{
_changeDifficultyLevel
(
'easy'
);
},
child:
Text
(
"Easy"
),
style:
ElevatedButton
.
styleFrom
(
primary:
const
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
// Custom color
),
),
SizedBox
(
width:
20
),
ElevatedButton
(
onPressed:
()
{
_changeDifficultyLevel
(
'medium'
);
},
child:
Text
(
"Medium"
),
style:
ElevatedButton
.
styleFrom
(
primary:
const
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
// Custom color
),
),
SizedBox
(
width:
20
),
ElevatedButton
(
onPressed:
()
{
_changeDifficultyLevel
(
'hard'
);
},
child:
Text
(
"Hard"
),
style:
ElevatedButton
.
styleFrom
(
primary:
const
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
// Custom color
),
),
],
),
const
SizedBox
(
height:
20
),
Container
(
width:
200
,
height:
60
,
child:
ElevatedButton
(
onPressed:
_pronounceWord
,
child:
const
Text
(
"Pronounce Word"
,
style:
TextStyle
(
fontSize:
20
),
),
style:
ElevatedButton
.
styleFrom
(
primary:
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
// Custom color
),
),
),
const
SizedBox
(
height:
20
),
Container
(
width:
200
,
height:
60
,
child:
ElevatedButton
(
onPressed:
_listenForPronunciation
,
child:
const
Text
(
"Listen for Pronunciation"
,
style:
TextStyle
(
fontSize:
20
),
),
style:
ElevatedButton
.
styleFrom
(
primary:
Color
.
fromARGB
(
255
,
39
,
20
,
204
),
// Custom color
),
),
),
const
SizedBox
(
height:
20
),
Text
(
"Your Pronunciation:
${userPronunciation ?? ''}
"
,
style:
const
TextStyle
(
fontSize:
25
),
),
Text
(
message
??
''
,
style:
const
TextStyle
(
fontSize:
25
),
),
],
),
),
),
),
bottomNavigationBar:
BottomAppBar
(
child:
Container
(
height:
50
,
child:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
Text
(
'Correct:
$correctCount
'
),
SizedBox
(
width:
20
),
Text
(
'Incorrect:
$incorrectCount
'
),
],
),
),
),
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment