Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Adds support for Mozilla Speech Services v2 #3340

Merged
merged 1 commit into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ dependencies {
annotationProcessor deps.room.compiler

// Android Components
implementation deps.mozilla_speech
implementation deps.mozilla_speech.library
implementation deps.mozilla_speech.utils
implementation deps.android_components.telemetry
implementation deps.android_components.browser_errorpages
implementation deps.android_components.browser_search
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import android.content.Context;
import android.content.res.Configuration;

import com.mozilla.speechlibrary.SpeechService;

import org.mozilla.vrbrowser.browser.Accounts;
import org.mozilla.vrbrowser.browser.Places;
import org.mozilla.vrbrowser.browser.Services;
Expand All @@ -30,6 +32,7 @@ public class VRBrowserApplication extends Application implements AppServicesProv
private Places mPlaces;
private Accounts mAccounts;
private DownloadsManager mDownloadsManager;
private SpeechService mSpeechService;

@Override
public void onCreate() {
Expand All @@ -46,6 +49,7 @@ protected void onActivityCreate() {
mServices = new Services(this, mPlaces);
mAccounts = new Accounts(this);
mDownloadsManager = new DownloadsManager(this);
mSpeechService = new SpeechService(this);
}

@Override
Expand Down Expand Up @@ -94,4 +98,9 @@ public Accounts getAccounts() {
public DownloadsManager getDownloadsManager() {
return mDownloadsManager;
}

@Override
public SpeechService getSpeechService() {
return mSpeechService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@ public class DownloadJob {
private String mFilename;
private String mTitle;
private String mDescription;
private String mOutputPath;

public static DownloadJob create(@NonNull String uri, @Nullable String contentType,
long contentLength, @Nullable String filename) {
return create(uri, contentType, contentLength, filename, null);
}

public static DownloadJob create(@NonNull String uri, @Nullable String contentType,
long contentLength, @Nullable String filename,
@Nullable String outputPath) {
DownloadJob job = new DownloadJob();
job.mUri = uri;
job.mContentType = contentType;
Expand All @@ -37,6 +44,7 @@ public static DownloadJob create(@NonNull String uri, @Nullable String contentTy
}
job.mTitle = filename;
job.mDescription = filename;
job.mOutputPath = outputPath;
return job;
}

Expand Down Expand Up @@ -156,4 +164,9 @@ public String getDescription() {
public void setDescription(String mDescription) {
this.mDescription = mDescription;
}

@Nullable
public String getOutputPath() {
return mOutputPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.mozilla.speechlibrary.utils.StorageUtils;

import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.utils.UrlUtils;

Expand Down Expand Up @@ -98,6 +100,10 @@ private void stopUpdates() {
}

public void startDownload(@NonNull DownloadJob job) {
startDownload(job, SettingsStore.getInstance(mContext).getDownloadsStorage());
}

public void startDownload(@NonNull DownloadJob job, @SettingsStore.Storage int storageType) {
if (!URLUtil.isHttpUrl(job.getUri()) && !URLUtil.isHttpsUrl(job.getUri())) {
notifyDownloadError("Cannot download non http/https files", job.getFilename());
return;
Expand All @@ -110,16 +116,21 @@ public void startDownload(@NonNull DownloadJob job) {
request.setMimeType(job.getContentType());
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setVisibleInDownloadsUi(false);
if (SettingsStore.getInstance(mContext).getDownloadsStorage() == SettingsStore.EXTERNAL) {
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, job.getFilename());
if (job.getOutputPath() == null) {
if (storageType == SettingsStore.EXTERNAL) {
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, job.getFilename());

} else {
String outputPath = getOutputPathForJob(job);
if (outputPath == null) {
notifyDownloadError("Cannot create output file", job.getFilename());
return;
} else {
String outputPath = getOutputPathForJob(job);
if (outputPath == null) {
notifyDownloadError("Cannot create output file", job.getFilename());
return;
}
request.setDestinationUri(Uri.parse(outputPath));
}
request.setDestinationUri(Uri.parse(outputPath));

} else {
request.setDestinationUri(Uri.parse("file://" + job.getOutputPath()));
}

if (mDownloadManager != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.mozilla.vrbrowser.ui.widgets;

import com.mozilla.speechlibrary.SpeechService;

import org.mozilla.vrbrowser.AppExecutors;
import org.mozilla.vrbrowser.browser.Accounts;
import org.mozilla.vrbrowser.browser.Places;
Expand All @@ -19,5 +21,5 @@ public interface AppServicesProvider {
BitmapCache getBitmapCache();
Accounts getAccounts();
DownloadsManager getDownloadsManager();

SpeechService getSpeechService();
}
Original file line number Diff line number Diff line change
Expand Up @@ -1257,18 +1257,13 @@ public void onGlobalFocusChanged(View oldFocus, View newFocus) {

// VoiceSearch Delegate
@Override
public void OnVoiceSearchResult(String aTranscription, float confidance) {
public void OnVoiceSearchResult(String aTranscription, float confidence) {
if (aTranscription != null && !aTranscription.isEmpty()) {
handleText(aTranscription);
}
exitVoiceInputMode();
}

@Override
public void OnVoiceSearchCanceled() {
exitVoiceInputMode();
}

@Override
public void OnVoiceSearchError() {
exitVoiceInputMode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ public void onDrmButtonClicked() {
// VoiceSearch Delegate

@Override
public void OnVoiceSearchResult(String transcription, float confidance) {
public void OnVoiceSearchResult(String transcription, float confidence) {
mBinding.navigationBarNavigation.urlBar.handleURLEdit(transcription);
}

Expand Down
Loading