Added audio recorder files and speech callbacks
This commit is contained in:
33
.idea/workspace.xml
generated
33
.idea/workspace.xml
generated
@@ -15,11 +15,10 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="00599d5b-7eb5-44da-ad7f-98bf42384c16" name="Changes" comment="Changes">
|
||||
<change afterPath="$PROJECT_DIR$/src/app/res/activity_main.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/app/src/main/com/fitbot/MainActivity.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/app/src/main/com/fitbot/audio/AudioRecorder.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/app/src/main/com/fitbot/chat/ISpeechCallback.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/app/src/main/com/fitbot/chat/SpeechGenerator.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/app/src/main/AndroidManifest.xml" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/src/main/AndroidManifest.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/app/src/main/com/fitbot/audio/AudioRecorder.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/src/main/com/fitbot/audio/AudioRecorder.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -33,12 +32,24 @@
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Class" />
|
||||
<option value="Interface" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="Git.Merge.Settings">
|
||||
<option name="BRANCH" value="origin/main" />
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="GitSEFilterConfiguration">
|
||||
<file-type-list>
|
||||
<filtered-out-file-type name="LOCAL_BRANCH" />
|
||||
<filtered-out-file-type name="REMOTE_BRANCH" />
|
||||
<filtered-out-file-type name="TAG" />
|
||||
<filtered-out-file-type name="COMMIT_BY_MESSAGE" />
|
||||
</file-type-list>
|
||||
</component>
|
||||
<component name="ProjectId" id="2fE3N2CwEPDo9wBtexBLxU20tCJ" />
|
||||
<component name="ProjectLevelVcsManager">
|
||||
<ConfirmationsSetting value="2" id="Add" />
|
||||
@@ -56,7 +67,7 @@
|
||||
<property name="project.structure.last.edited" value="SDKs" />
|
||||
<property name="project.structure.proportion" value="0.1322751" />
|
||||
<property name="project.structure.side.proportion" value="0.3937198" />
|
||||
<property name="settings.editor.selected.configurable" value="preferences.lookFeel" />
|
||||
<property name="settings.editor.selected.configurable" value="preferences.keymap" />
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
@@ -69,6 +80,14 @@
|
||||
<workItem from="1713352368383" duration="57000" />
|
||||
<workItem from="1713352446871" duration="1766000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="Changes">
|
||||
<created>1713528225837</created>
|
||||
<option name="number" value="00001" />
|
||||
<option name="presentableId" value="LOCAL-00001" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1713528225837</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="2" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
@@ -86,4 +105,8 @@
|
||||
</option>
|
||||
<option name="oldMeFiltersMigrated" value="true" />
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="Changes" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Changes" />
|
||||
</component>
|
||||
</project>
|
10
src/app/src/main/com/fitbot/audio/AudioAnalyser.java
Normal file
10
src/app/src/main/com/fitbot/audio/AudioAnalyser.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.fitbot.audio;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.media.MediaRecorder;
|
||||
|
||||
public class AudioAnalyser extends Activity {
|
||||
|
||||
|
||||
|
||||
}
|
@@ -1,13 +1,8 @@
|
||||
package com.fitbot.audio;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.media.MediaRecorder;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class AudioRecorder extends Activity {
|
||||
public class AudioRecorder {
|
||||
|
||||
private MediaRecorder recorder;
|
||||
|
||||
@@ -23,13 +18,9 @@ public class AudioRecorder extends Activity {
|
||||
|
||||
recorder = new MediaRecorder();
|
||||
|
||||
File file = new File()
|
||||
|
||||
FileInputStream stream = new FileInputStream();
|
||||
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
|
||||
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
|
||||
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
|
||||
recorder.setOutputFile(stream.getFD());
|
||||
|
||||
// Attempt to prepare and start the audio recorder
|
||||
try {
|
||||
@@ -40,8 +31,6 @@ public class AudioRecorder extends Activity {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
recorder.set
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -54,4 +43,5 @@ public class AudioRecorder extends Activity {
|
||||
recorder = null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
8
src/app/src/main/com/fitbot/speech/ISpeechCallback.java
Normal file
8
src/app/src/main/com/fitbot/speech/ISpeechCallback.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package com.fitbot.speech;
|
||||
|
||||
/**
|
||||
* Interface for a callback that is called when speech is generated
|
||||
*/
|
||||
public interface ISpeechCallback {
|
||||
void onSpeechGenerated(String speech);
|
||||
}
|
89
src/app/src/main/com/fitbot/speech/SpeechGenerator.java
Normal file
89
src/app/src/main/com/fitbot/speech/SpeechGenerator.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package com.fitbot.speech;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
public class SpeechGenerator {
|
||||
|
||||
private ISpeechCallback speechCallback = (content) -> {}; // Default empty callback
|
||||
private StringBuilder speechBuffer = new StringBuilder(); // Buffer to store the speech content
|
||||
private String languageIso639_1; // ISO 639-1 language code
|
||||
|
||||
/**
|
||||
* Constructor that sets the language of the speech to be generated
|
||||
* @param languageIso639_1 The ISO 639-1 language code, e.g. "en" for English
|
||||
*/
|
||||
public SpeechGenerator(String languageIso639_1)
|
||||
{
|
||||
if ( !Arrays.asList(Locale.getISOLanguages()).contains(languageIso639_1) )
|
||||
throw new IllegalArgumentException("Invalid language code");
|
||||
this.languageIso639_1 = languageIso639_1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor, sets the language to English
|
||||
*/
|
||||
public SpeechGenerator()
|
||||
{
|
||||
this("en");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the language of the speech to be generated
|
||||
* @param languageIso639_1 The ISO 639-1 language code, e.g. "en" for English
|
||||
* @return An instance of the SpeechGenerator class
|
||||
*/
|
||||
public SpeechGenerator language(String languageIso639_1)
|
||||
{
|
||||
this.languageIso639_1 = languageIso639_1;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the provided text to the speech buffer
|
||||
* @param text The text to append
|
||||
* @return An instance of the SpeechGenerator class
|
||||
*/
|
||||
public SpeechGenerator print(String text)
|
||||
{
|
||||
speechBuffer.append(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the provided text to the speech buffer, followed by a newline character
|
||||
* @param text The text to append
|
||||
* @return An instance of the SpeechGenerator class
|
||||
*/
|
||||
public SpeechGenerator println(String text)
|
||||
{
|
||||
return print(text).print("\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contents of the speech buffer
|
||||
*/
|
||||
public String getBuffer()
|
||||
{
|
||||
return speechBuffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the contents of the speech buffer
|
||||
*/
|
||||
public void clearBuffer()
|
||||
{
|
||||
speechBuffer = new StringBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the contents of the speech buffer to the console
|
||||
*/
|
||||
public void speak()
|
||||
{
|
||||
speechCallback.onSpeechGenerated(speechBuffer.toString());
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user