Aplikasi Artificial Intelligence Speech To Text Berbasis Mobile Android

Assalamu'alaikum Wr.Wb

            Di tutorial saya kali ini, saya akan mencoba membuat project tentang mobile programming dengan software android studio "Aplikasi Artificial Intelligence Speech To Text Berbasis Mobile Android. Didalam Aplikasi Artificial Intelligence Speech To Text terdapat menu tab host sebagai tampilan awalnya.


Penjelasan tentang kecerdasan buatan / Artificial Intelligence
Kecerdasan buatan atau artificial intelligence merupakan bagian dari ilmu komputer yang membuat agar mesin (komputer) dapat melakukan pekerjaan seperti dan sebaik yang dilakukan oleh manusia. Sistem cerdas (intelligent system) adalah sistem yang dibangun dengan menggunakan teknik-teknik artificial intelligence. Salah satu yang dipelajari pada kecerdasan buatan adalah teori Sistem Pakar. (Kusumadewi, 2003)

Ini adalah tugas kelompok kami yang beranggotakan :

                                     NIM                          NAMA
161011401382      Adji Tulus Pangestu
161021401428      Harun Usman
161011401406      Rizkon Sidik Mustaqim
                               161021401485      Sinta Rahamadani 

Langkah - langkah pembuatannya >>>
Didalam project kami terdapat 3 Activity.java yaitu :

1. MainActivity.java
2. SpeechToText.java
3. Kompas.java

Dan terdapat 3 Activity.xml yaitu :

1. activity_main.xml
2. activity_speech_to_text.xml
3. activity_kompas.xml

Langkah pertama mari kita buat source code activity_main.xml :

a.) Activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="bottom" />

    </LinearLayout>
</TabHost>



b.) activity_speech_to_text.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    >

    <TextView
        android:typeface="serif"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="153dp"
        android:id="@+id/inputSuara"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:textSize="18sp"
        android:textColor="@android:color/black"
        tools:text="Text Hasil Inputan disini"/>

    <Button
        android:text="Tap To Speech"
        android:typeface="serif"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/tombolBicara"
        android:background="@android:color/holo_green_light"/>

</RelativeLayout>

c.) activity_kompas.xml


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#141414"
    android:foregroundGravity="center|center_horizontal"
    android:focusableInTouchMode="false">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/background_light"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignTop="@+id/tvHeading"
        android:layout_marginTop="-62dp" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="120dp"
        android:src="@drawable/prompt"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignTop="@+id/tvHeading"
        android:layout_marginTop="-62dp"
        android:id="@+id/imageView" />

    <TextView
        android:id="@+id/tvHeading"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="40dp"
        android:layout_marginTop="40dp"
        android:text="Heading 0"
        android:textColor="#ffffff"
        android:typeface="serif"
        android:textSize="28dp" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="120dp"
        android:src="@drawable/background_compass"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignTop="@+id/tvHeading"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="-39dp"
        android:layout_marginRight="15dp"
        android:layout_marginLeft="15dp" />

    <ImageView
        android:id="@+id/imageViewCompass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/compass"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginRight="17dp"
        android:layout_marginLeft="17dp" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="120dp"
        android:src="@drawable/miui_cover"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignTop="@+id/tvHeading"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="-40dp"
        android:layout_marginRight="20dp"
        android:layout_marginLeft="20dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="- APP BY - \STMIK ERESHA"
        android:id="@+id/textView"
        android:textAlignment="center"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="20dp"
        android:textColor="#acacac"
        android:typeface="serif"
        android:textSize="18dp" />

</RelativeLayout>


Langkah kedua mari kita buat source code mainactivity.java :

a.)  MainActivity.java


package com.example.aiapplication;

import android.os.Bundle;
import android.app.TabActivity;
import android.content.Intent;
import android.widget.TabHost;

@SuppressWarnings("deprecation")
public class MainActivity extends TabActivity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TabHost tabhost = getTabHost();
        TabHost.TabSpec spec;
        Intent intent;

        intent = new Intent().setClass(this, SpeechToText.class);
        spec = tabhost.newTabSpec("STT").setIndicator("Speech To Text",null).setContent(intent);
        tabhost.addTab(spec);//untuk membuat tabbaru disini bisa diatur sesuai keinginan anda

        intent = new Intent().setClass(this, Kompas.class);
        spec = tabhost.newTabSpec("KOMPAS").setIndicator("Kompas",null).setContent(intent);
        tabhost.addTab(spec);
    }
}

b.) SpeechToText.java

package com.example.aiapplication;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Locale;

public class SpeechToText extends AppCompatActivity {

    private TextView inputSuara;
    private Button tombolBicara;
    private final int REQ_CODE_SPEECH_INPUT = 100;

    //deklarasi var atau object
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_speech_to_text);


        getSupportActionBar().setTitle("Speech To Text");
        getSupportActionBar().setSubtitle("APP BY - STMIK ERESHA");

        inputSuara = (TextView) findViewById(R.id.inputSuara);

        tombolBicara = (Button) findViewById(R.id.tombolBicara);


        tombolBicara.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tanyaInputSuara();
            }
        });
    }

    // Untuk menampilkan Google speech input dialog
    public void tanyaInputSuara() {
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
                "Hei Katakan sesuatu ");

        try {
            startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
        } catch (ActivityNotFoundException a) {

        }

    }

    //Untuk menerima inputan speech dan menampilkan text
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);


        Toast.makeText(this, "Hasil suara ditampilkan", Toast.LENGTH_SHORT).show();
        switch (requestCode) {
            case REQ_CODE_SPEECH_INPUT: {
                if (resultCode == RESULT_OK && null != data) {

                    ArrayList<String> result = data
                            .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                    inputSuara.setText(result.get(0));
                }
                break;
            }

        }
    }
}

c.) Kompas.java

package com.example.aiapplication;

import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.TextView;

public class Kompas extends Activity implements SensorEventListener {

    // define the display assembly compass picture
    private ImageView image;

    // record the compass picture angle turned
    private float currentDegree = 0f;

    // device sensor manager
    private SensorManager mSensorManager;

    TextView tvHeading;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kompas);

// our compass image
        image = (ImageView) findViewById(R.id.imageViewCompass);

// TextView that will tell the user what degree is he heading
        tvHeading = (TextView) findViewById(R.id.tvHeading);

// initialize your android device sensor capabilities
        mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    }


    @Override
    protected void onResume() {
        super.onResume();

// for the system's orientation sensor registered listeners
        mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
                SensorManager.SENSOR_DELAY_GAME);
    }

    @Override
    protected void onPause() {
        super.onPause();

// to stop the listener and save battery
        mSensorManager.unregisterListener(this);
    }

    @Override
    public void onSensorChanged(SensorEvent event) {

// get the angle around the z-axis rotated
        float degree = Math.round(event.values[0]);

        tvHeading.setText("Heading " + Float.toString(degree) + "°");

// create a rotation animation (reverse turn degree degrees)
        RotateAnimation ra = new RotateAnimation(
                currentDegree,
                -degree,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF,
                0.5f);

// how long the animation will take place
        ra.setDuration(60);

// set the animation after the end of the reservation status
        ra.setFillAfter(true);

// Start the animation
        image.startAnimation(ra);
        currentDegree = -degree;

    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
// not in use
    }
}

Tampilan Design :

a.) Tampilan awal ketika dirun

b.) Tampilan ketika tombol button tap to speech di klik


c.) Tampilan aplikasi speech to text tidak mengenali suara


d.) Tampilan aplikasi speech to text mengenali suara




e.) Tampilan output aplikasi speech to text 




Mohon maaf bila masih ada kekurangan ditutorial kami, semoga bermanfaat.

Sekian dan terimakasih ^_^

Wassalamu'alaikum Wr.Wb

Komentar

Postingan Populer