Skip to content

Commit

Permalink
refact: files structure
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamSilveiraF committed Oct 25, 2023
1 parent f2eaf87 commit 3435ad0
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions api/routes/audio.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi import APIRouter, UploadFile, File, HTTPException
from pathlib import Path
from api.services.transcribe_audio import transcribe_model_selection
from services.transcribe_audio import transcribe_audio_content

import os

Expand All @@ -23,7 +23,7 @@ async def upload_audio(file: UploadFile = File(...)):
with open(path_to_audio, 'wb') as f:
f.write(data)

audio_text = transcribe_model_selection(path_to_audio)
audio_text = transcribe_audio_content(path_to_audio)

return {"filename": file.filename, "message": "File uploaded successfully!"}
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi import FastAPI
from api.routes import audio
from api.middlewares import cors_middleware
from middlewares import cors_middleware

app = FastAPI()

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from google.cloud import speech

def transcribe_model_selection(speech_file: str) -> speech.RecognizeResponse:
def transcribe_audio_content(speech_file: str) -> speech.RecognizeResponse:

client = speech.SpeechClient()

Expand All @@ -9,7 +9,7 @@ def transcribe_model_selection(speech_file: str) -> speech.RecognizeResponse:

audio = speech.RecognitionAudio(content=content)

config = speech.RecognitionConfig(
config = speech.RecognitionConfig( # TODO SUPPORT DIFFERENT TYPES OF AUDIO
encoding=speech.RecognitionConfig.AudioEncoding.ENCODING_UNSPECIFIED,
sample_rate_hertz=16000,
language_code="en-US",
Expand All @@ -19,8 +19,5 @@ def transcribe_model_selection(speech_file: str) -> speech.RecognizeResponse:

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}")

return response

return alternative.transcript

0 comments on commit 3435ad0

Please sign in to comment.