Kirthana L
Created September 4, 2024

Seeing AI: Android App for Visually Impaired

Seeing AI is an Android app that uses OCR and TTS to convert text from images into audio.

15
Seeing AI: Android App for Visually Impaired

Things used in this project

Hardware components

nRF52 Development Kit
Nordic Semiconductor nRF52 Development Kit
×1
ESP8266 ESP-01
Espressif ESP8266 ESP-01
×1

Software apps and online services

Android Studio
Android Studio

Story

Read more

Code

Seeing AI

Java
Requesting camera permission and capturing an image using the device's camera.
Performing OCR on the captured image using the Google Cloud Vision API or other OCR libraries.
Converting the recognized text to speech using the TextToSpeech class provided by Android.
public class SeeingAIActivity extends AppCompatActivity {

    private static final int REQUEST_IMAGE_CAPTURE = 1;
    private static final int REQUEST_PERMISSION = 2;

    private TextToSpeech textToSpeech;

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

        // Initialize TextToSpeech
        textToSpeech = new TextToSpeech(this, status -> {
            if (status == TextToSpeech.SUCCESS) {
                // TTS initialization successful
            }
        });

        // Request camera permission
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, REQUEST_PERMISSION);
        } else {
            captureImage();
        }
    }

    private void captureImage() {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            Bitmap imageBitmap = (Bitmap) extras.get("data");

            // Perform OCR on the captured image
            String recognizedText = performOCR(imageBitmap);

            // Convert recognized text to speech
            textToSpeech.speak(recognizedText, TextToSpeech.QUEUE_FLUSH, null, null);
        }
    }

    private String performOCR(Bitmap bitmap) {
        // Use Google Cloud Vision API or other OCR libraries to extract text from the image
        // Return the recognized text as a string
        return "This is a sample recognized text.";
    }
}

Credits

Kirthana L

Kirthana L

1 project • 1 follower

Comments