Moved files to appropriate directory.

This commit is contained in:
Luca Warmenhoven
2024-04-19 14:47:27 +02:00
parent 11517ca2f0
commit ead909c457
8 changed files with 32 additions and 39 deletions

View File

@@ -0,0 +1,18 @@
package com.fitbot;
import android.app.Activity;
import android.media.MediaRecorder;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* Since this is our main activity, we can start our audio recording service here */
}
}

View File

@@ -0,0 +1,10 @@
package com.fitbot.audio;
import android.app.Activity;
import android.media.MediaRecorder;
public class AudioAnalyser {
}

View File

@@ -0,0 +1,47 @@
package com.fitbot.audio;
import android.media.MediaRecorder;
public class AudioRecorder {
private MediaRecorder recorder;
public AudioRecorder() {
}
/**
* Record audio from the device's microphone
* @return An instance of the AudioRecorder class
*/
public AudioRecorder record() {
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
// Attempt to prepare and start the audio recorder
try {
recorder.prepare();
recorder.start();
} catch (Exception e) {
System.err.println("Error preparing audio recorder");
e.printStackTrace();
}
return this;
}
/**
* Stop the audio recording
*/
public void stop() {
recorder.stop();
recorder.release();
recorder = null;
}
}

View File

@@ -1,13 +0,0 @@
package com.fitbot.fitbot;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testlayout); // replace with your layout file
}
}

View File

@@ -1,18 +0,0 @@
package com.fitbot.fitbot;
import android.app.Activity;
import android.widget.TextView;
public class TextSetter {
public static void setCustomText(Activity activity, int textViewId, String text) {
TextView textView = (TextView) activity.findViewById(textViewId);
textView.setText(text);
}
}
// usage:
// TextSetter.setCustomText(this, R.id.testText, "Bruh");
// r.id.testText is the id of the textview in the layout file
// "Bruh" is the text to be set
// make sure you have the right layout set in MainActivity.java with the setContentView method

View 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);
}

View 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());
}
}