Skip to content
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

Adding Voice Commands Feature #897

Open
wants to merge 1,629 commits into
base: main
Choose a base branch
from
Open

Adding Voice Commands Feature #897

wants to merge 1,629 commits into from

Conversation

WailB
Copy link

@WailB WailB commented Jun 16, 2017

These changes are adding voice commands button to the app. Current
commands are found under voice_commands.xml. This can be expanded to add
commands to audio control or change settings as well. A microphone button can be found on top of the main screen.

Ahmed Abdelaal and others added 30 commits October 3, 2016 22:10
Many people have complained about not being to import. This patch adds
an actual import preference, which just fires off an ACTION_GET_CONTENT
intent. On Kitkat and above, the Storage Access Framework gives people
the option to import from applications that are document providers (ex
Dropbox, Google Drive, etc). On older devices, this usually offers a
file picker as an option. Fixes quran#634.
Make the headers for "Current Page", "Page Bookmarks", and "Not Tagged"
not clickable (since they do nothing when clicked or long clicked).
Clean up some code.
Most of these LTR hardcodes are needed for supporting pre-api 17. To fix
this, split out layout-ar and layout-ar-v17, with the latter being an
exact copy of the respective files from layout.

Some of the other cases (the various ViewPager indicators) actually
always receive data in the correct order, so they need to be LTR. These
cases have been placed in the code instead. It should be possible to
remove  some of these explicit layout direction attributes in the
future after some additional work.
In cases when the calculated dropdown width is less than the width of
the actual spinner, use that width as the dropdown width. This stops
certain sura names from being cut off.
adding an .editorconfig file to the repo so that new contributors will automatically have their formatting setup correctly.

It's built into Android Studio. Settings->Editor->Code Style then Check "Enable EditorConfig".
The .editorconfig used to adress .java and .sh solely. Since the code style guide says that
2 spaces is used throughout the project. I've changed .editorconfig to use 2 spaces throughout
the project.
This also makes "missing translations" a warning instead of an error.
This is supported by Android Studio and IntelliJ and is important for
keeping consistency with the existing code style.
This implements recent pages for Quran (using similar behavior to Quran
for iOS). A table of recent pages now exists within the bookmarks
database. Whenever a Quran page is selected, it is added to the table.
When the page changes, the new page replaces the old one in recents. The
recents table currently maintains a maximum of 3 items. Fixes quran#691.
RxPreferences was used for listening to changes on the last page. Now
that this code has changes, this is no longer needed. Will consider
adding it back in the future if needed insha'Allah.
ahmedre and others added 19 commits May 20, 2017 01:26
This removes the 150 search limit when doing a search (though the limit
intentionally remains for suggestions). Fixes quran#791.
The api contains a languageCode as of version 4. Store this in the
database as it can help optimize search queries.
Since we know when a query is or isn't Arabic, we can use this
information to skip databases that are Arabic when the query isn't
Arabic (or that aren't Arabic when the query is Arabic).
This patch returns results from the first database that has results.
This is done for performance and to avoid having to sort the results.
In translation mode, long pressing an ayah now shows a toolbar (similar
to the one in the images screen), but with the share menu. Choosing to
copy or share will copy the verse in Arabic (if it is not disabled in
the settings) followed by all currently enabled translations as text,
and then copy or share.
Many people complain that they are asked to redownload images on every
start of the app. This adds some logging to help identify the problem.
To account for the arabic database, i starts at -1 if it's present.
Consequently, there shouldn't be an additional 1 added to the total
count, because that results in a clear out of bounds case.
May Allah reward brother Mohamed Omar for preparing these 4 sets. These
are sets for sheikh Saad al Ghamidi, sheikh Bandar Baleela, sheikh
Mahmoud Ali al Bana, and sheikh Abdulrahman Al Shahat.
These changes are adding voice commands button to the app. Current
commands are found under voice_commands.xml. This can be expanded to add
commands to audio control or change settings as well.
Adding microphone icon to fix the error
To fix the error
@@ -21,7 +22,12 @@
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

/////////////////////////////////////////////
//voice commands imports
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this comment

@@ -65,6 +71,12 @@
R.string.quran_juz2,
R.string.quran_sura };

///////////////////////////////////////////////////
//Used for Voice Commands
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this comment

else {
CharSequence text = "";
if(language.equals("ar-SA"))
text = " لا يوجد الامر " + S + " الرجاء الاعادة ";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not use hard coded text, use text from strings.xml

Modified the code to include recommended changes.
Copy link
Contributor

@ozbek ozbek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, "voice commands" looks immature and not suitable for production in its current logic and implementation. You may need to put more thought on its core logic.

@@ -22,6 +23,10 @@
import android.view.MenuInflater;
import android.view.MenuItem;

import android.speech.RecognizerIntent;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please organize imports. Current order is alphabetic.

private static final int SPEECH_REQUEST_CODE = 0;
private VoiceCommandsUtil voiceCom;


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant empty line, please remove.

@@ -118,6 +127,10 @@ public void onCreate(Bundle savedInstanceState) {
(SlidingTabLayout) findViewById(R.id.indicator);
indicator.setViewPager(pager);


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@@ -118,6 +127,10 @@ public void onCreate(Bundle savedInstanceState) {
(SlidingTabLayout) findViewById(R.id.indicator);
indicator.setViewPager(pager);


voiceCom = new VoiceCommandsUtil(QuranActivity.this);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@@ -265,7 +283,34 @@ protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}

private void jumpToLastPage() {
public void startVoiceRecognition() {
final String language = QuranSettings.getInstance(this).isArabicNames() ? "ar-SA" : "en-US";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are essentially limiting voice recognition to Arabic and US English. Both Google voice recognition and the Qur'an app supports more locales. Please consider taking that into account.

myContext.startActivity(i);
return true;
case 5:
sura = 2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am having hard time understanding the logic here. Why are we jumping to Surah Baqarah here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The voice command is to go to Sura Al-Bagarah. However, I missed adding it in the english xml file. It is in the arabic file. The intention is to make it easy for the user to jump to the required Sura through voice instead of having to type the name in the "Jump" option or scroll to it.

@@ -286,4 +286,7 @@
</plurals>
<string name="undo">تراجع</string>

<!-- voice Commands strings -->
<string name="commandNotFound">جرب مرة أخرى. الأمر التالي غير موجود = </string>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<string name="command_not_found">

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the comment here?

@@ -0,0 +1,12 @@
<?xml version='1.0' encoding='utf-8'?>
<resources>
<string name="vChoice">اذكر الامر المطلوب</string>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vChoice <--- please make it more descriptive.

<?xml version='1.0' encoding='utf-8'?>
<resources>
<string name="vChoice">اذكر الامر المطلوب</string>
<string-array name="voiceCommandsList">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<string-array name="voice_commands_list">

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the comment here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using camel case in the markup attributes, 'voiceCommandsList' should be 'voice_commands_list'.

build.gradle Outdated
@@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:2.3.3'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest you make an independent PR for the changes in build.gradle

@WailB
Copy link
Author

WailB commented Jun 23, 2017

Thank you for your comments. I just want to clarify, this is just a basic code just to show that it works. The core code is there, all is needed is to add "features" to it by adding to the case function in VoiceCommandsUtil.java. I might eluded in my previous posts and probably can be seen in my slow progress, I don't have that much time to work on this to make it a full fledged feature. I am hoping that with this code someone can work on it to add more features to it to make it useful for people. If not, I'll keep working on it as time permits until it is completed.

Also, I will make the code cleaner with more descriptive comments. But you have raised a very good issue, its hard for someone new like myself to read the master code and understand the different functions since there is almost no comments or explanations. Even the order of imports being alphabetical is not clear. So, I suggest an effort to be made to add comments to help new collaborators hit the ground running.

WailB added 2 commits July 4, 2017 01:26
This is a major overhaul of the code to comply with comments received
and add additional features such as going to specific pages both in
arabic and english. Currently this codes allows to go to suras in arabic
and english (only english translated names, also 2 suras are not
currently working Qaf and Jinn). You can change the voice commands
language as well.
returning gradle build to 2.3.0 as per ozbek comment
@WailB
Copy link
Author

WailB commented Jul 3, 2017

Please let me know if there are any additional comments or feel free to work on the code yourself. Just a few items to clarify:

  • I understand the comment about not hard coding strings. However, I had to do it for 2 special cases for an English sura search. This is the best way I could think of to make it easy to search without complicated sentences since the translated sura names are longer than one word. I couldn't use the Arabic version of the English names because google recognition software had difficulty capturing many of the name.
  • Two of the English translated sura names (Qaf and Jinn) couldn't be found by the voice recognition software. The rest can be identified according to my own testing. I am open to suggestions on how to handle those 2 suras.
  • The list of voice commands both in Arabic and English can be found in strings voice_commands.xml (the default one) as well as the strings used for searching. The reason I didn't separate them is because of the system language locale issue. The localized xml files can be only accessed if the system language is changed. This limits the functionality of the software if someone wants to use the Arabic voice recognition while the system language is English (such as in my case). The other option was to play around with the configuration locale by changing it back and forth but I read that it is not recommended to do that.
  • The command to go to specific page is "page 7" for example.
  • The command to go to specific sura is "go to the opener" for example. No need to say sura/surat. In fact to avoid bad recognition of words, the code will only care about the last word (except for the two special cases mentioned in the code)
  • The command to change the language to Arabic is "language arabic" then you can immediately start giving commands in Arabic the next time you click the microphone.
  • There are also commands "settings", "help" and "about"
  • The possibilities are endless. Additional features can be added such as changing settings directly without opening the settings page (similar to changing the language of the recognition software) or opening translation or tafseers, or searching for specific words, or start audio recitations, etc. This will require a lot more time from me because I still haven't figured out the rest of the code. It is difficult to understand without any comments.

Made some optimization to the code to make it cleaner and added arabic
root word code to help make the commands more flexible. For example, the
user can say ذهب او اذهب او ذهاب  as a command to go to a sura.
@ahmedre ahmedre force-pushed the master branch 2 times, most recently from acf48be to f4d3065 Compare October 14, 2017 19:11
@sanginovs
Copy link

@ahmedre what is the update on this PR?
Can someone else take over? If yes, can you please describe the voice command feature in more detail. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.