### Install Dependencies with Pip Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/amharic-speech-service/README.md This command installs all the necessary Python packages listed in the 'requirements.txt' file, ensuring the project has all its dependencies met. ```bash pip install -r requirements.txt ``` -------------------------------- ### Listening Exercise (free_text) JSON Example Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.2 Lisan Exercise JSON schemas.md This JSON structure defines a listening comprehension exercise where the user listens to audio and types the entire sentence they hear. It includes the audio prompt and the correct full sentence. ```json { "id": "ls_003", "type": "listening", "subtype": "free_text", "instruction": "Type what you hear", "data": { "prompt_audio_url": "https://cdn.example.com/audio/full_sentence.mp3", "correct_answer": "ከየት ነህ?" } } ``` -------------------------------- ### Listening Exercise (block_build) JSON Example Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.2 Lisan Exercise JSON schemas.md This JSON structure defines a listening comprehension exercise where the user listens to audio and arranges blocks of text to form the correct sentence. It includes the audio prompt, the available blocks, and the correct sentence. ```json { "id": "ls_004", "type": "listening", "subtype": "block_build", "instruction": "Tap what you hear", "data": { "prompt_audio_url": "https://cdn.example.com/audio/ls_004.mp3", "blocks": ["እየሄድኩ", "ትምህርት", "ነው", "ቤት"], "correct_answer": "ትምህርት ቤት እየሄድኩ ነው" } } ``` -------------------------------- ### Direct Translation Exercise (free_text) JSON Example Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.2 Lisan Exercise JSON schemas.md This JSON structure defines a direct translation exercise where the user manually types the translation. It includes the prompt text, an audio URL for pronunciation, and the correct translation. ```json { "id": "tr_002", "type": "translation", "subtype": "free_text", "instruction": "Translate this sentence", "data": { "prompt_text": "I love to read books.", "prompt_audio_url": "https://cdn.example.com/audio/tr_002.mp3", "correct_answer": "መጽሐፍ ማንበብ እወዳለሁ።" } } ``` -------------------------------- ### Complete Sentence Exercise (partial_free_text) JSON Example Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.2 Lisan Exercise JSON schemas.md This JSON structure defines an exercise to complete a sentence by typing the missing part. It includes the reference text, the sentence with a blank, and the correct word to fill the blank. ```json { "id": "cs_001", "type": "complete_sentence", "subtype": "partial_free_text", "instruction": "Complete the sentence", "data": { "reference_text": "She is a doctor.", "display_text": "እሷ ____ ናት።", "correct_answer": "ሀኪም" } } ``` -------------------------------- ### Speaking Exercise JSON Example Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.2 Lisan Exercise JSON schemas.md This JSON structure defines a speaking exercise where the user is prompted to speak a sentence aloud. It includes the prompt text and an audio URL for the correct pronunciation. ```json { "id": "sp_001", "type": "speaking", "instruction": "Speak this sentence aloud", "data": { "prompt_text": "ሰላም እንዴት ነህ?", "prompt_audio_url": "https://cdn.example.com/audio/sp_001.mp3", "correct_answer": "ሰላም እንዴት ነህ?" } } ``` -------------------------------- ### Python Virtual Environment Setup Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/amharic-speech-service/README.md This snippet demonstrates how to create and activate a Python virtual environment, a recommended practice for isolating project dependencies. It uses standard Python commands. ```bash python -m venv venv virtualenv_path=$(pwd)/venv/Scripts/activate source virtualenv_path ``` -------------------------------- ### Direct Translation Exercise (block_build) JSON Example Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.2 Lisan Exercise JSON schemas.md This JSON structure defines a direct translation exercise where the user constructs the translation from provided blocks of text. It includes the prompt text, an audio URL for pronunciation, the available blocks, and the correct translation. ```json { "id": "tr_001", "type": "translation", "subtype": "block_build", "instruction": "Translate this sentence", "data": { "prompt_text": "My brother is taller than my sister.", "prompt_audio_url": "https://cdn.example.com/audio/tr_001.mp3", "blocks": ["ይረዝማል", "ከእህቴ", "ወንድሜ"], "correct_answer": "ወንድሜ ከእህቴ ይረዝማል" } } ``` -------------------------------- ### Listening Exercise (choose_missing) JSON Example Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.2 Lisan Exercise JSON schemas.md This JSON structure defines a listening comprehension exercise where the user listens to audio and chooses the missing word from a list of options. It includes an audio prompt, the sentence with a blank, and audio options for each choice. ```json { "id": "ls_001", "type": "listening", "subtype": "omit_word_choose", "instruction": "Listen and choose the correct missing word.", "data": { "prompt_audio_url": "https://cdn.example.com/audio/ls_001.mp3", "display_text": "እሷ ____ ትወዳለች።", "options": [ { "id": 0, "option_audio_url": "https://cdn.example.com/audio/ls_001_1.mp3", "text": "ቡና" }, { "id": 1, "option_audio_url": "https://cdn.example.com/audio/ls_001_2.mp3", "text": "ሻይ" } ], "correct_option_id": 1 } } ``` -------------------------------- ### Complete Sentence Exercise (partial_block_build) JSON Example Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.2 Lisan Exercise JSON schemas.md This JSON structure defines an exercise to complete a sentence by arranging blocks of text to form the missing part. It includes the reference text, the sentence with blanks, the available blocks, and the complete correct sentence. ```json { "id": "cs_002", "type": "complete_sentence", "subtype": "partial_block_build", "instruction": "Complete the sentence", "data": { "reference_text": "This beautiful flower smells good.", "display_text": "ይህ ____ አበባ ጥሩ ____ አለው።", "blocks": ["ቆንጆ", "መዓዛ", "ቀለም"], "correct_answer": "ይህ ቆንጆ አበባ ጥሩ መዓዛ አለው" } } ``` -------------------------------- ### Listening Exercise (type_missing) JSON Example Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.2 Lisan Exercise JSON schemas.md This JSON structure defines a listening comprehension exercise where the user listens to audio and types the missing word. It includes the audio prompt, the sentence with a blank, and the correct missing word. ```json { "id": "ls_002", "type": "listening", "subtype": "omit_word_type", "instruction": "Listen and type the missing word.", "data": { "prompt_audio_url": "https://cdn.example.com/audio/ls_002.mp3", "display_text": "ዛሬ በጣም ____ ነው።", "correct_answer": "ትኩስ" } } ``` -------------------------------- ### Fill in the Blank Exercise (one missing word) JSON Example Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.2 Lisan Exercise JSON schemas.md This JSON structure defines a fill-in-the-blank exercise where one word is missing from a sentence. It provides the sentence with a blank, multiple options for the missing word, and the ID of the correct option. ```json { "id": "fb_001", "type": "fill_in_blank", "instruction": "Choose the correct word for the blank.", "data": { "display_text": "እኔ ____ እጠጣለሁ።", "options": [ { "id": 0, "text": "ውሃ" }, { "id": 1, "text": "ዳቦ" }, { "id": 2, "text": "ወንበር" } ], "correct_option_id": 1 } } ``` -------------------------------- ### Run FastAPI Application Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/amharic-speech-service/README.md This command starts the FastAPI web service. The API will then be accessible at the specified local address, typically http://localhost:8000. ```bash python main.py ``` -------------------------------- ### Fill in the Blank Exercise (two missing words) JSON Example Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.2 Lisan Exercise JSON schemas.md This JSON structure defines a fill-in-the-blank exercise with two missing words in a sentence. It provides the sentence with two blanks, options containing pairs of words, and the ID of the correct pair. ```json { "id": "fb_002", "type": "fill_in_blank", "instruction": "Select the pair that best fits the blanks.", "data": { "display_text": "____ ከገበያ ____ ገዛች።", "options": [ { "id": 0, "text": "እሱ ... ዳቦ" }, { "id": 1, "text": "እሷ ... አትክልት" }, { "id": 1, "text": "እነሱ ... ወተት" } ], "correct_option_id": 2 } } ``` -------------------------------- ### Audio Text Matching Pairs Example (JSON) Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.3 Lisan Exercise JSON schemas.md This JSON structure defines a matching pairs exercise for the 'audio_text' subtype. It includes instructions, audio elements with URLs, text elements, and the correct pairings between them. This format is used to create interactive lessons. ```json { "id": "mp_lesson_001", "type": "matching_pairs", "subtype": "audio_text", "instruction": "Tap the matching pairs", "data": { "left_items": [ { "id": "audio_1", "audio_url": "assets/mp_lesson_voices/mp_001_1.mp3" }, { "id": "audio_2", "audio_url": "assets/mp_lesson_voices/mp_001_2.mp3" }, { "id": "audio_3", "audio_url": "assets/mp_lesson_voices/mp_001_3.mp3" }, { "id": "audio_4", "audio_url": "assets/mp_lesson_voices/mp_001_4.mp3" }, { "id": "audio_5", "audio_url": "assets/mp_lesson_voices/mp_001_5.mp3" }, { "id": "audio_6", "audio_url": "assets/mp_lesson_voices/mp_001_6.mp3" }, { "id": "audio_7", "audio_url": "assets/mp_lesson_voices/mp_001_7.mp3" }, { "id": "audio_8", "audio_url": "assets/mp_lesson_voices/mp_001_8.mp3" }, { "id": "audio_9", "audio_url": "assets/mp_lesson_voices/mp_001_9.mp3" }, { "id": "audio_10", "audio_url": "assets/mp_lesson_voices/mp_001_10.mp3" }, { "id": "audio_11", "audio_url": "assets/mp_lesson_voices/mp_001_11.mp3" }, { "id": "audio_12", "audio_url": "assets/mp_lesson_voices/mp_001_12.mp3" }, { "id": "audio_13", "audio_url": "assets/mp_lesson_voices/mp_001_13.mp3" }, { "id": "audio_14", "audio_url": "assets/mp_lesson_voices/mp_001_14.mp3" }, { "id": "audio_15", "audio_url": "assets/mp_lesson_voices/mp_001_15.mp3" }, { "id": "audio_16", "audio_url": "assets/mp_lesson_voices/mp_001_16.mp3" }, { "id": "audio_17", "audio_url": "assets/mp_lesson_voices/mp_001_17.mp3" }, { "id": "audio_18", "audio_url": "assets/mp_lesson_voices/mp_001_18.mp3" }, { "id": "audio_19", "audio_url": "assets/mp_lesson_voices/mp_001_19.mp3" }, { "id": "audio_20", "audio_url": "assets/mp_lesson_voices/mp_001_20.mp3" } ], "right_items": [ { "id": "text_a", "text": "Chair" }, { "id": "text_b", "text": "Table" }, { "id": "text_c", "text": "Water" }, { "id": "text_d", "text": "House" }, { "id": "text_e", "text": "Milk" }, { "id": "text_f", "text": "Book" }, { "id": "text_g", "text": "Pencil" }, { "id": "text_h", "text": "Door" }, { "id": "text_i", "text": "Window" }, { "id": "text_j", "text": "Bed" }, { "id": "text_k", "text": "Food" }, { "id": "text_l", "text": "Coffee" }, { "id": "text_m", "text": "Tea" }, { "id": "text_n", "text": "Car" }, { "id": "text_o", "text": "Road" }, { "id": "text_p", "text": "Tree" }, { "id": "text_q", "text": "Flower" }, { "id": "text_r", "text": "Sky" }, { "id": "text_s", "text": "Sun" }, { "id": "text_t", "text": "Moon" } ], "correct_pairs": [ { "left_id": "audio_1", "right_id": "text_a" }, { "left_id": "audio_2", "right_id": "text_b" }, { "left_id": "audio_3", "right_id": "text_c" }, { "left_id": "audio_4", "right_id": "text_d" }, { "left_id": "audio_5", "right_id": "text_e" }, { "left_id": "audio_6", "right_id": "text_f" }, { "left_id": "audio_7", "right_id": "text_g" }, { "left_id": "audio_8", "right_id": "text_h" }, { "left_id": "audio_9", "right_id": "text_i" }, { "left_id": "audio_10", "right_id": "text_j" }, { "left_id": "audio_11", "right_id": "text_k" }, { "left_id": "audio_12", "right_id": "text_l" }, { "left_id": "audio_13", "right_id": "text_m" }, { "left_id": "audio_14", "right_id": "text_n" }, { "left_id": "audio_15", "right_id": "text_o" }, { "left_id": "audio_16", "right_id": "text_p" }, { "left_id": "audio_17", "right_id": "text_q" }, { "left_id": "audio_18", "right_id": "text_r" }, { "left_id": "audio_19", "right_id": "text_s" }, { "left_id": "audio_20", "right_id": "text_t" } ] } } ``` -------------------------------- ### Listening Exercise: Choose Missing Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.3 Lisan Exercise JSON schemas.md Defines a listening exercise where the user listens to audio and chooses the correct missing word from options. Includes prompt audio, display text with a blank, and audio options with text. ```json { "id": "ls_001", "type": "listening", "subtype": "choose_missing", "instruction": "Listen and choose the correct missing word.", "data": { "prompt_audio_url": "https://cdn.example.com/audio/ls_001.mp3", "display_text": "እሷ ____ ትወዳለች።", "options": [ { "id": 0, "option_audio_url": "https://cdn.example.com/audio/ls_001_1.mp3", "text": "ቡና" }, { "id": 1, "option_audio_url": "https://cdn.example.com/audio/ls_001_2.mp3", "text": "ሻይ" } ], "correct_option_id": 1 } } ``` -------------------------------- ### Complete Sentence Exercise: Partial Free Text Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.3 Lisan Exercise JSON schemas.md Defines an exercise to complete a sentence by typing the missing part. Includes reference text, display text with a blank, and the correct answer. ```json { "id": "cs_001", "type": "complete_sentence", "subtype": "partial_free_text", "instruction": "Complete the sentence", "data": { "reference_text": "She is a doctor.", "display_text": "እሷ ____ ናት።", "correct_answer": "እሷ ሀኪም ናት።" } } ``` -------------------------------- ### Fill-in-the-Blank Exercise: One Missing Word Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.3 Lisan Exercise JSON schemas.md Defines a fill-in-the-blank exercise with one missing word. Includes display text with a blank, a list of options with their IDs, and the correct option ID. ```json { "id": "fb_001", "type": "fill_in_blank", "instruction": "Choose the correct word for the blank.", "data": { "display_text": "እኔ ____ እጠጣለሁ።", "options": [ { "id": 0, "text": "ውሃ" }, { "id": 1, "text": "ዳቦ" }, { "id": 2, "text": "ወንበር" } ], "correct_option_id": 1 } } ``` -------------------------------- ### Audio-Text Matching Pairs Configuration (JSON) Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.3 Lisan Exercise JSON schemas.md Defines a JSON structure for audio-to-text matching pairs. It includes a list of audio segments and corresponding text identifiers, along with the correct pairings. ```json { "id": "mp_lesson_001", "type": "matching_pairs", "subtype": "audio_text", "instruction": "Tap the matching pairs", "data": { "left_items": [ { "id": "audio_1", "audio": "audio_1.mp3" }, { "id": "audio_2", "audio": "audio_2.mp3" } ], "right_items": [ { "id": "text_s", "text": "Pair S" }, { "id": "text_t", "text": "Pair T" } ], "correct_pairs": [ { "left_id": "audio_1", "right_id": "text_s" }, { "left_id": "audio_2", "right_id": "text_t" } ] } } ``` -------------------------------- ### Fill-in-the-Blank Exercise: Two Missing Words Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.3 Lisan Exercise JSON schemas.md Defines a fill-in-the-blank exercise with two missing words. Includes display text with blanks, a list of combined options, and the correct option ID. ```json { id": "fb_002", "type": "fill_in_blank", "instruction": "Select the pair that best fits the blanks.", "data": { "display_text": "____ ከገበያ ____ ገዛች።", "options": [ { "id": 0, "text": "እሱ ... ዳቦ" }, { "id": 1, "text": "እሷ ... አትክልት" }, { "id": 1, "text": "እነሱ ... ወተት" } ], "correct_option_id": 2 } } ``` -------------------------------- ### Listening Exercise: Type Missing Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.3 Lisan Exercise JSON schemas.md Defines a listening exercise where the user listens to audio and types the missing word. Includes prompt audio, display text with a blank, and the correct answer. ```json { "id": "ls_002", "type": "listening", "subtype": "type_missing", "instruction": "Listen and type the missing word.", "data": { "prompt_audio_url": "https://cdn.example.com/audio/ls_002.mp3", "display_text": "ዛሬ በጣም ____ ነው።", "correct_answer": "ትኩስ" } } ``` -------------------------------- ### Text-Text Matching Pairs Configuration (JSON) Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.3 Lisan Exercise JSON schemas.md Defines a JSON structure for text-to-text matching pairs, commonly used for language learning. It lists left and right text items in two languages and specifies the correct associations. ```json { "id": "mp_lesson_002", "type": "matching_pairs", "subtype": "text_text", "instruction": "Tap the matching pairs", "data": { "left_items": [ { "id": "amharic_1", "text": "ቤት" }, { "id": "amharic_2", "text": "ውሃ" } ], "right_items": [ { "id": "english_a", "text": "Pencil" }, { "id": "english_b", "text": "House" } ], "correct_pairs": [ { "left_id": "amharic_1", "right_id": "english_b" }, { "left_id": "amharic_2", "right_id": "english_d" } ] } } ``` -------------------------------- ### Picture Multiple Choice JSON Structure Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/lesson-service/v1.3 Lisan Exercise JSON schemas.md Defines the JSON structure for a picture multiple choice question. It includes question details, options with image URLs and labels, and the correct answer. This format is likely used for presenting image-based selection tasks to users. ```json { "id": "pc_001", "type": "picture_multiple_choice", "subtype": "block_build", "instruction": "Select the correct image", "data": { "prompt_text": "በሬ", "options": [ { "id": 0, "image_url": "assets/images/picture_choice (1).png", "label": "Cat" }, { "id": 1, "image_url": "assets/images/picture_choice (2).png", "label": "Ox" }, { "id": 2, "image_url": "assets/images/picture_choice (3).png", "label": "Dog" }, { "id": 3, "image_url": "assets/images/picture_choice (4).png", "label": "Sheep" } ], "correct_option_id": 1 } } ``` -------------------------------- ### Curl Text-to-Speech Request Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/amharic-speech-service/README.md This cURL command demonstrates how to send a POST request to the /text-to-speech endpoint to convert Amharic text into speech. It specifies the content type and provides the text and desired voice in the JSON body. ```bash curl -X POST "http://localhost:8000/text-to-speech" \ -H "Content-Type: application/json" \ -d '{"text": "ሰላም ወንድሜ", "voice": "am-ET-MekdesNeural"}' ``` -------------------------------- ### Speech-to-Text API Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/amharic-speech-service/README.md Converts an uploaded Amharic audio file into text using SpeechBrain's Wav2Vec2 model. Supports audio files up to 10MB. ```APIDOC ## POST /speech-to-text ### Description Upload an audio file (max 10MB) for transcription into Amharic text. ### Method POST ### Endpoint /speech-to-text ### Parameters #### Query Parameters None #### Request Body - **audio_file** (file) - Required - The audio file to be transcribed (e.g., WAV, MP3). ### Request Example ```bash curl -X POST "http://localhost:8000/speech-to-text" \ -F "audio_file=@your_audio.wav" ``` ### Response #### Success Response (200) - **transcription** (string) - The transcribed Amharic text. #### Response Example ```json { "transcription": "የአማርኛ ንግግር አገልግሎት" } ``` ``` -------------------------------- ### Curl Speech-to-Text Request Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/amharic-speech-service/README.md This cURL command shows how to send an audio file to the /speech-to-text endpoint for transcription. It uses the '-F' flag to upload a file, specifying the audio file's path. ```bash curl -X POST "http://localhost:8000/speech-to-text" \ -F "audio_file=@your_audio.wav" ``` -------------------------------- ### Text-to-Speech API Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/amharic-speech-service/README.md Converts Amharic text into speech audio using Microsoft Edge TTS. Allows selection of male or female voices. ```APIDOC ## POST /text-to-speech ### Description Convert Amharic text into speech audio. Supports specific male and female voices. ### Method POST ### Endpoint /text-to-speech ### Parameters #### Query Parameters None #### Request Body - **text** (string) - Required - The Amharic text to convert to speech. - **voice** (string) - Optional - The voice to use for synthesis. Defaults to `am-ET-MekdesNeural`. Supported values: `am-ET-MekdesNeural` (female), `am-ET-AmehaNeural` (male). ### Request Example ```json { "text": "ሰላም ወንድሜ", "voice": "am-ET-MekdesNeural" } ``` ### Response #### Success Response (200) - **audio_content** (string) - Base64 encoded audio data of the generated speech. #### Response Example ```json { "audio_content": "/9j/4AAQSkZJRgABAQEAS... (Base64 encoded audio data)" } ``` ``` -------------------------------- ### Health Check API Source: https://github.com/abelxkassahun/lesan-microservice/blob/main/amharic-speech-service/README.md Checks the health status of the Amharic Speech Service and the availability of its models. ```APIDOC ## GET /health ### Description Check service status and model availability. ### Method GET ### Endpoint /health ### Parameters ### Request Example ``` GET /health ``` ### Response #### Success Response (200) - **status** (string) - Indicates if the service is operational. - **models_available** (boolean) - Indicates if the required models are loaded and ready. #### Response Example ```json { "status": "operational", "models_available": true } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.