Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
TMP-23-390
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TMP-23-390
TMP-23-390
Commits
3ae29db0
Commit
3ae29db0
authored
Nov 06, 2023
by
Vidura Randika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new file
parent
f8f20f84
Pipeline
#7190
failed with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
0 deletions
+95
-0
Dockerfile
Dockerfile
+95
-0
No files found.
Dockerfile
0 → 100644
View file @
3ae29db0
# 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"]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment