forked from Cleveroad/WaveInApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implemented speech recognizer dBm handler * updated rendering logic * renamed resources and attributes * updated readme
- Loading branch information
Showing
27 changed files
with
847 additions
and
206 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.cleveroad.example; | ||
|
||
import android.os.Bundle; | ||
import android.support.v4.app.ListFragment; | ||
import android.view.View; | ||
import android.widget.AdapterView; | ||
import android.widget.ArrayAdapter; | ||
|
||
/** | ||
* Main fragment. | ||
*/ | ||
public class MainFragment extends ListFragment implements AdapterView.OnItemClickListener { | ||
|
||
public static MainFragment newInstance() { | ||
return new MainFragment(); | ||
} | ||
|
||
@Override | ||
public void onViewCreated(View view, Bundle savedInstanceState) { | ||
super.onViewCreated(view, savedInstanceState); | ||
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(), R.array.selection_items, android.R.layout.simple_list_item_1); | ||
setListAdapter(adapter); | ||
getListView().setOnItemClickListener(this); | ||
} | ||
|
||
@Override | ||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | ||
if (position == 0) { | ||
getActivity().getSupportFragmentManager().beginTransaction() | ||
.replace(R.id.container, AudioVisualizationFragment.newInstance()) | ||
.addToBackStack(null) | ||
.commit(); | ||
} else if (position == 1) { | ||
getActivity().getSupportFragmentManager().beginTransaction() | ||
.replace(R.id.container, SpeechRecognitionFragment.newInstance()) | ||
.addToBackStack(null) | ||
.commit(); | ||
} | ||
} | ||
} |
147 changes: 147 additions & 0 deletions
147
app/src/main/java/com/cleveroad/example/SpeechRecognitionFragment.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package com.cleveroad.example; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.speech.RecognitionListener; | ||
import android.speech.RecognizerIntent; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
|
||
import com.cleveroad.audiovisualization.AudioVisualization; | ||
import com.cleveroad.audiovisualization.DbmHandler; | ||
import com.cleveroad.audiovisualization.SpeechRecognizerDbmHandler; | ||
|
||
/** | ||
* Fragment with audio visualization view. | ||
*/ | ||
public class SpeechRecognitionFragment extends Fragment { | ||
|
||
public static SpeechRecognitionFragment newInstance() { | ||
return new SpeechRecognitionFragment(); | ||
} | ||
|
||
private AudioVisualization audioVisualization; | ||
private Button btnRecognize; | ||
private SpeechRecognizerDbmHandler handler; | ||
private boolean recognizing; | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
View view = inflater.inflate(R.layout.fragment_gles, container, false); | ||
audioVisualization = (AudioVisualization) view.findViewById(R.id.visualizer_view); | ||
btnRecognize = (Button) view.findViewById(R.id.btn_recognize); | ||
return view; | ||
} | ||
|
||
@Override | ||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
super.onViewCreated(view, savedInstanceState); | ||
btnRecognize.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if (recognizing) { | ||
handler.stopListening(); | ||
} else { | ||
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); | ||
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); | ||
handler.startListening(intent); | ||
} | ||
btnRecognize.setEnabled(false); | ||
} | ||
}); | ||
handler = DbmHandler.newSpeechRecognizerHandler(getContext()); | ||
handler.innerRecognitionListener(new SimpleRecognitionListener() { | ||
|
||
@Override | ||
public void onReadyForSpeech(Bundle params) { | ||
super.onReadyForSpeech(params); | ||
onStartRecognizing(); | ||
} | ||
|
||
@Override | ||
public void onResults(Bundle results) { | ||
super.onResults(results); | ||
onStopRecognizing(); | ||
} | ||
|
||
@Override | ||
public void onError(int error) { | ||
super.onError(error); | ||
onStopRecognizing(); | ||
|
||
} | ||
}); | ||
audioVisualization.linkTo(handler); | ||
} | ||
|
||
private void onStopRecognizing() { | ||
recognizing = false; | ||
btnRecognize.setText(R.string.start_recognition); | ||
btnRecognize.setEnabled(true); | ||
} | ||
|
||
private void onStartRecognizing() { | ||
btnRecognize.setText(R.string.stop_recognition); | ||
btnRecognize.setEnabled(true); | ||
recognizing = true; | ||
} | ||
|
||
@Override | ||
public void onDestroyView() { | ||
audioVisualization.release(); | ||
super.onDestroyView(); | ||
} | ||
|
||
private static class SimpleRecognitionListener implements RecognitionListener { | ||
|
||
@Override | ||
public void onReadyForSpeech(Bundle params) { | ||
|
||
} | ||
|
||
@Override | ||
public void onBeginningOfSpeech() { | ||
|
||
} | ||
|
||
@Override | ||
public void onRmsChanged(float rmsdB) { | ||
|
||
} | ||
|
||
@Override | ||
public void onBufferReceived(byte[] buffer) { | ||
|
||
} | ||
|
||
@Override | ||
public void onEndOfSpeech() { | ||
|
||
} | ||
|
||
@Override | ||
public void onError(int error) { | ||
|
||
} | ||
|
||
@Override | ||
public void onResults(Bundle results) { | ||
|
||
} | ||
|
||
@Override | ||
public void onPartialResults(Bundle partialResults) { | ||
|
||
} | ||
|
||
@Override | ||
public void onEvent(int eventType, Bundle params) { | ||
|
||
} | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,15 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<com.cleveroad.audiovisualization.GLAudioVisualizationView | ||
<RelativeLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:id="@+id/visualizer_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:bubble_size="@dimen/bubble_size" | ||
app:randomize_bubble_size="true" | ||
app:wave_height="@dimen/wave_height" | ||
app:footer_height="@dimen/footer_height" | ||
app:waves_count="7" | ||
app:layers_count="4" | ||
app:background_color="@color/color_bg" | ||
/> | ||
> | ||
<com.cleveroad.audiovisualization.GLAudioVisualizationView | ||
android:id="@+id/visualizer_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:av_bubble_size="@dimen/bubble_size" | ||
app:av_randomize_bubble_size="true" | ||
app:av_wave_height="@dimen/wave_height" | ||
app:av_footer_height="@dimen/footer_height" | ||
app:av_waves_count="7" | ||
app:av_layers_count="4" | ||
app:av_background_color="@color/av_color_bg" | ||
/> | ||
|
||
<Button | ||
android:id="@+id/btn_recognize" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
style="@style/Widget.AppCompat.Button.Borderless" | ||
android:text="@string/start_recognition" | ||
android:layout_alignParentBottom="true" | ||
/> | ||
</RelativeLayout> |
This file contains 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string-array name="selection_items"> | ||
<item>Visualizer</item> | ||
<item>Speech Recognizer</item> | ||
</string-array> | ||
</resources> |
This file contains 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 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 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.