Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-garavini committed Aug 15, 2024
1 parent 9acf645 commit 0c3582a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
2 changes: 0 additions & 2 deletions custom_components/openai_whisper_cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

_LOGGER = logging.getLogger(__name__)

CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
Expand Down
1 change: 1 addition & 0 deletions custom_components/openai_whisper_cloud/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ async def validate_input(data: dict):
url="https://api.openai.com/v1/models",
headers={
"Authorization": f"Bearer {data.get(CONF_API_KEY)}",
"Content-Type": "application/json"
},
)

Expand Down
17 changes: 5 additions & 12 deletions custom_components/openai_whisper_cloud/stt.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ def __init__(self, api_key, model, temperature, prompt, name, unique_id) -> None
self._attr_name = name
self._attr_unique_id = unique_id

@property
def default_language(self) -> str:
"""Return the default language."""
return "en"

@property
def supported_languages(self) -> list[str]:
"""Return a list of supported languages."""
Expand Down Expand Up @@ -146,17 +141,15 @@ async def async_process_audio_stream(
)

# Parse the JSON response
transcription = response.json()

_LOGGER.debug(transcription)
transcription = response.json().get("text", "")

# Retrieve the transcribed text
transcribed_text = transcription.get("text", "")
_LOGGER.debug("TRANSCRIPTION: %s", transcription)

if not transcribed_text:
if not transcription:
_LOGGER.error("No transcription received")
return SpeechResult("", SpeechResultState.ERROR)

return SpeechResult(transcribed_text, SpeechResultState.SUCCESS)
return SpeechResult(transcription, SpeechResultState.SUCCESS)

except requests.exceptions.RequestException as e:
_LOGGER.error(e)
Expand Down

0 comments on commit 0c3582a

Please sign in to comment.