-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: set transcribe_model_selection
- Loading branch information
1 parent
80d3b90
commit 360badd
Showing
7 changed files
with
64 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from fastapi.middleware.cors import CORSMiddleware | ||
|
||
def setup_cors(app): | ||
origins = [ | ||
"http://localhost:3000", | ||
] | ||
|
||
app.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=origins, | ||
allow_credentials=True, | ||
allow_methods=["*"], | ||
allow_headers=["*"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
from google.cloud import speech | ||
from google.cloud.speech import enums, types | ||
|
||
def transcribe_audio(file_path): | ||
def transcribe_model_selection(speech_file: str) -> speech.RecognizeResponse: | ||
|
||
client = speech.SpeechClient() | ||
|
||
with open(file_path, "rb") as audio_file: | ||
with open(speech_file, "rb") as audio_file: | ||
content = audio_file.read() | ||
|
||
audio = types.RecognitionAudio(content=content) | ||
config = types.RecognitionConfig( | ||
encoding=enums.RecognitionConfig.AudioEncondig.LINEAR16, | ||
# TODO: Adjuste sample rate | ||
audio = speech.RecognitionAudio(content=content) | ||
|
||
config = speech.RecognitionConfig( | ||
encoding=speech.RecognitionConfig.AudioEncoding.ENCODING_UNSPECIFIED, | ||
sample_rate_hertz=16000, | ||
language_code="en-US" | ||
language_code="en-US", | ||
) | ||
|
||
response = client.recognize(config=config, audio=audio) | ||
|
||
for i, result in enumerate(response.results): | ||
alternative = result.alternatives[0] | ||
print("-" * 20) | ||
print(f"First alternative of result {i}") | ||
print(f"Transcript: {alternative.transcript}") | ||
|
||
if response.results: | ||
return response.results[0].alternatives[0].transcript | ||
return "" | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
from fastapi import FastAPI | ||
from api.routes import audio | ||
from api.middlewares import cors_middleware | ||
|
||
app = FastAPI() | ||
|
||
cors_middleware.setup_cors(app) | ||
|
||
app.include_router(audio.router) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters