Commit 3ae29db0 authored by Vidura Randika's avatar Vidura Randika

Add new file

parent f8f20f84
Pipeline #7190 failed with stages
# This file is a template, and might need editing before it works on your project.
# This Dockerfile installs a compiled binary into a bare system.
# You must either commit your compiled binary into source control (not recommended)
# or build the binary first as part of a CI/CD pipeline.
FROM buildpack-deps:jessie
import os
import io
import json
import time
import pyaudio
import speech_recognition as sr
from google.cloud import speech_v1p1beta1
from google.cloud import translate
# Set your Google Cloud JSON key file path
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "path/to/your-key-file.json"
def record_audio():
audio = pyaudio.PyAudio()
stream = audio.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=1024)
frames = []
print("Listening...")
try:
while True:
data = stream.read(1024)
frames.append(data)
except KeyboardInterrupt:
print("Recording stopped.")
finally:
stream.stop_stream()
stream.close()
audio.terminate()
return b''.join(frames)
def speech_to_text(audio_data):
client = speech_v1p1beta1.SpeechClient()
config = {
"language_code": "en-US",
}
audio = {"content": audio_data}
response = client.recognize(config=config, audio=audio)
return response.results[0].alternatives[0].transcript
def translate_text(text):
client = translate.TranslationServiceClient()
parent = client.location_path("your-project-id", "global")
response = client.translate_text(
parent=parent,
contents=[text],
target_language_code="si", # Sinhala language code
)
return response.translations[0].translated_text
if __name__ == "__main__":
audio_data = record_audio()
transcribed_text = speech_to_text(audio_data)
print("Transcribed Text:", transcribed_text)
translated_text = translate_text(transcribed_text)
print("Translated Text (Sinhala):", translated_text)
import deepspeech
import wave
import numpy as np
# Load the DeepSpeech model
model = deepspeech.Model("path/to/your/model.pb")
# Create a stream for audio input
ds_stream = model.createStream()
# Open an audio file for recognition
audio_file = "path/to/your/sinhala_audio.wav"
# Read the audio file and recognize the text
with wave.open(audio_file, "rb") as wf:
rate = wf.getframerate()
audio_data = wf.readframes(wf.getnframes())
audio_data = np.frombuffer(audio_data, np.int16)
text = model.stt(audio_data)
print("Recognized Text (Sinhala):", text)
WORKDIR /usr/local/bin
# Change `app` to whatever your binary is called
Add app .
CMD ["./app"]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment