Skip to content

Commit

Permalink
chore: add support to pass definition for stt
Browse files Browse the repository at this point in the history
  • Loading branch information
ymshenyu committed Dec 11, 2024
1 parent ed1f849 commit cbdb514
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 9 additions & 2 deletions api/core/tools/provider/builtin/azurespeech/tools/asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> list[ToolInv
if file.type != FileType.AUDIO:
return [self.create_text_message("not a valid audio file")]
audio_binary = download(file)
definition: str = tool_parameters.get("definition", "")

files: dict = {"audio": audio_binary}
if definition:
files["definition"] = definition
resp = requests.post(
"https://{}.api.cognitive.microsoft.com/speechtotext/transcriptions:transcribe?api-version={}".format(
self.runtime.credentials.get("azure_speech_region"),
Expand All @@ -24,7 +28,7 @@ def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> list[ToolInv
headers={
"Ocp-Apim-Subscription-Key": self.runtime.credentials.get("azure_speech_api_key"),
},
files={"audio": audio_binary},
files=files,
)

data: dict = resp.json()
Expand All @@ -34,4 +38,7 @@ def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> list[ToolInv
if len(combinedPhrases) == 0:
raise Exception("No text detected, error: {}".format(json.dumps(data)))

return [self.create_text_message(data.get("combinedPhrases", [])[0].get("text", ""))]
return [
self.create_text_message(data.get("combinedPhrases", [])[0].get("text", "")),
self.create_json_message(data),
]
11 changes: 11 additions & 0 deletions api/core/tools/provider/builtin/azurespeech/tools/asr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ parameters:
zh_Hans: 要转换的音频文件。
llm_description: The audio file to be converted.
form: llm
- name: definition
type: string
required: false
label:
en_US: Definition
zh_Hans: asr 详细配置
human_description:
en_US: Definition
zh_Hans: asr 详细配置
llm_description: Definition
form: form

0 comments on commit cbdb514

Please sign in to comment.