-
-
Notifications
You must be signed in to change notification settings - Fork 180
feat: support audio in quizzes #1733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
huyenltnguyen
wants to merge
3
commits into
freeCodeCamp:main
Choose a base branch
from
huyenltnguyen:feat/quiz-audio
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,7 +67,7 @@ class Challenge { | |
|
|
||
| // English Challenges | ||
| final FillInTheBlank? fillInTheBlank; | ||
| final EnglishAudio? audio; | ||
| final EnglishScene? audio; | ||
| final Scene? scene; | ||
|
|
||
| // Nodules for interactive challenges | ||
|
|
@@ -125,7 +125,7 @@ class Challenge { | |
| ? FillInTheBlank.fromJson(data['fillInTheBlank']) | ||
| : null, | ||
| audio: data['scene'] != null | ||
| ? EnglishAudio.fromJson(data['scene']['setup']['audio']) | ||
| ? EnglishScene.fromJson(data['scene']['setup']['audio']) | ||
| : null, | ||
| tests: (data['tests'] ?? []) | ||
| .map<ChallengeTest>((file) => ChallengeTest.fromJson(file)) | ||
|
|
@@ -456,11 +456,13 @@ class QuizQuestion { | |
| final String text; | ||
| final List<Answer> answers; | ||
| final int solution; | ||
| final QuizAudioData? audioData; | ||
|
|
||
| const QuizQuestion({ | ||
| required this.text, | ||
| required this.answers, | ||
| required this.solution, | ||
| this.audioData, | ||
| }); | ||
|
|
||
| factory QuizQuestion.fromJson(Map<String, dynamic> data) { | ||
|
|
@@ -482,7 +484,13 @@ class QuizQuestion { | |
| allAnswers.indexWhere((a) => a.answer == data['answer']) + 1; | ||
|
|
||
| return QuizQuestion( | ||
| text: data['text'], answers: allAnswers, solution: solutionIndex); | ||
| text: data['text'], | ||
| answers: allAnswers, | ||
| solution: solutionIndex, | ||
| audioData: data['audioData'] != null | ||
| ? QuizAudioData.fromJson(data['audioData']) | ||
| : null, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -526,7 +534,7 @@ class Scene { | |
| class SceneSetup { | ||
| final String background; | ||
| final bool? alwaysShowDialogue; | ||
| final EnglishAudio audio; | ||
| final EnglishScene audio; | ||
| final List<SceneCharacter> characters; | ||
|
|
||
| const SceneSetup({ | ||
|
|
@@ -539,7 +547,7 @@ class SceneSetup { | |
| factory SceneSetup.fromJson(Map<String, dynamic> data) { | ||
| return SceneSetup( | ||
| background: data['background'], | ||
| audio: EnglishAudio.fromJson(data['audio']), | ||
| audio: EnglishScene.fromJson(data['audio']), | ||
| characters: data['characters'] | ||
| .map<SceneCharacter>( | ||
| (character) => SceneCharacter.fromJson(character), | ||
|
|
@@ -642,25 +650,96 @@ class SceneDialogue { | |
| } | ||
| } | ||
|
|
||
| class EnglishAudio { | ||
| abstract class AudioClip { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implemented a shared class so both scene and quiz audio can share audio logic. (I did try to make the scene and quiz audio schema as close as possible for this purpose). |
||
| String get fileName; | ||
| String? get startTimeStamp; | ||
| String? get finishTimeStamp; | ||
| } | ||
|
|
||
| class EnglishScene implements AudioClip { | ||
| @override | ||
| final String fileName; | ||
| final String startTime; | ||
| @override | ||
| final String? startTimeStamp; | ||
| @override | ||
| final String? finishTimeStamp; | ||
|
|
||
| const EnglishAudio({ | ||
| const EnglishScene({ | ||
| required this.fileName, | ||
| required this.startTime, | ||
| required this.startTimeStamp, | ||
| required this.finishTimeStamp, | ||
| }); | ||
|
|
||
| factory EnglishAudio.fromJson(Map<String, dynamic> data) { | ||
| return EnglishAudio( | ||
| factory EnglishScene.fromJson(Map<String, dynamic> data) { | ||
| return EnglishScene( | ||
| fileName: data['filename'], | ||
| startTime: data['startTime'].toString(), | ||
| startTimeStamp: data['startTimestamp']?.toString(), | ||
| finishTimeStamp: data['finishTimestamp']?.toString(), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class QuizTranscriptLine { | ||
| final String character; | ||
| final String text; | ||
|
|
||
| const QuizTranscriptLine({ | ||
| required this.character, | ||
| required this.text, | ||
| }); | ||
|
|
||
| factory QuizTranscriptLine.fromJson(Map<String, dynamic> data) { | ||
| return QuizTranscriptLine( | ||
| character: data['character'], | ||
| text: data['text'], | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class QuizAudio implements AudioClip { | ||
| @override | ||
| final String fileName; | ||
| @override | ||
| final String? startTimeStamp; | ||
| @override | ||
| final String? finishTimeStamp; | ||
|
|
||
| const QuizAudio({ | ||
| required this.fileName, | ||
| this.startTimeStamp, | ||
| this.finishTimeStamp, | ||
| }); | ||
|
|
||
| factory QuizAudio.fromJson(Map<String, dynamic> data) { | ||
| return QuizAudio( | ||
| fileName: data['filename'], | ||
| startTimeStamp: data['startTimestamp']?.toString(), | ||
| finishTimeStamp: data['finishTimestamp']?.toString(), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class QuizAudioData { | ||
| final QuizAudio audio; | ||
| final List<QuizTranscriptLine> transcript; | ||
|
|
||
| const QuizAudioData({ | ||
| required this.audio, | ||
| required this.transcript, | ||
| }); | ||
|
|
||
| factory QuizAudioData.fromJson(Map<String, dynamic> data) { | ||
| final audioData = data['audio']; | ||
| return QuizAudioData( | ||
| audio: QuizAudio.fromJson(audioData), | ||
| transcript: (data['transcript'] as List) | ||
| .map<QuizTranscriptLine>( | ||
| (item) => QuizTranscriptLine.fromJson(item), | ||
| ) | ||
| .toList(), | ||
| ); | ||
| } | ||
| } | ||
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm adding a new
QuizAudioclass so I renamedEnglishAudiotoEnglishScene, to better differentiate the two.