Skip to content

Commit 0aa4912

Browse files
committed
manual fix
1 parent 1e220a9 commit 0aa4912

File tree

6 files changed

+36
-32
lines changed

6 files changed

+36
-32
lines changed

.env.template

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ AZURE_BLOB_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=https;AccountName
1515
AZURE_BLOB_STORAGE_CONTAINER_NAME="files"
1616

1717
# Azure AI Speech
18-
AZURE_SPEECH_KEY="<YOUR_SPEECH_KEY>"
19-
AZURE_SPEECH_REGION="<YOUR_SPEECH_REGION>"
20-
AZURE_SPEECH_ENDPOINT="https://<YOUR_SPEECH_REGION>.api.cognitive.microsoft.com/"
18+
AZURE_AI_SPEECH_API_KEY="<YOUR_AZURE_AI_SPEECH_API_KEY>"
19+
AZURE_AI_SPEECH_ENDPOINT="https://<speech-api-name>.cognitiveservices.azure.com/"

docs/index.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,32 +76,39 @@ uv run python scripts/files.py delete-multiple-files "file1.txt" "file2.jpg" "fi
7676
### Speeches Service
7777

7878
```shell
79+
AZURE_BLOB_STORAGE_CONTAINER_SAS_TOKEN="<your_sas_token>"
80+
AZURE_BLOB_STORAGE_CONTAINER_URL="https://<storage_account_name>.blob.core.windows.net/<container_name>"
81+
FILE_NAME="path/to/your/audio/file.wav"
82+
URL="${AZURE_BLOB_STORAGE_CONTAINER_URL}/${FILE_NAME}?${AZURE_BLOB_STORAGE_CONTAINER_SAS_TOKEN}"
83+
7984
# Help
8085
uv run python scripts/speeches.py --help
8186

8287
# Create a new transcription job
83-
uv run python scripts/speeches.py create-transcription "https://example.com/audio.wav" --locale "ja-JP" --name "My Transcription"
88+
uv run python scripts/speeches.py create-transcription "$URL" \
89+
--locale "ja-JP" \
90+
--name "My Transcription"
8491

8592
# Get transcription job status
86-
uv run python scripts/speeches.py get-transcription JOB_ID
93+
uv run python scripts/speeches.py get-transcription "$JOB_ID"
94+
95+
# Wait for transcription completion
96+
uv run python scripts/speeches.py wait-for-completion "$JOB_ID" --timeout 300 --interval 10
8797

8898
# Get transcription files
89-
uv run python scripts/speeches.py get-transcription-files JOB_ID
99+
uv run python scripts/speeches.py get-transcription-files "$JOB_ID"
90100

91101
# Get transcription result
92-
uv run python scripts/speeches.py get-transcription-result "https://example.com/result.json" --save "result.json"
102+
uv run python scripts/speeches.py get-transcription-result "https://<contentUrl>" --save "result.json"
93103

94104
# List all transcription jobs
95105
uv run python scripts/speeches.py list-transcriptions
96106

97-
# Wait for transcription completion
98-
uv run python scripts/speeches.py wait-for-completion JOB_ID --timeout 300 --interval 10
99-
100107
# Delete transcription job
101-
uv run python scripts/speeches.py delete-transcription JOB_ID
108+
uv run python scripts/speeches.py delete-transcription "$JOB_ID"
102109

103110
# Delete transcription job (without confirmation)
104-
uv run python scripts/speeches.py delete-transcription JOB_ID --force
111+
uv run python scripts/speeches.py delete-transcription "$JOB_ID" --force
105112
```
106113

107114
## MCP
@@ -157,3 +164,7 @@ az resource update \
157164
- [FastAPI のテレメトリデータを Azure Application Insights に送る](https://qiita.com/hoto17296/items/2f366dfabdbe3d1d4e97)
158165
- [【Azure Functions】 - Application Insights のログが表示されない問題](https://zenn.dev/headwaters/articles/ff19f7e1b99b44)
159166
- [opentelemetry-instrumentation-fastapi (python) から OpenTelemetry に入門する](https://zenn.dev/taxin/articles/opentelemetry-fast-api-instrumentation-basics)
167+
168+
### Azure AI Speech
169+
170+
- [バッチ文字起こしとは](https://learn.microsoft.com/ja-jp/azure/ai-services/speech-service/batch-transcription)

scripts/speeches.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def create_transcription(
2222
content_urls: list[str] = typer.Argument(..., help="転写するファイルのURL(複数指定可能)"),
2323
locale: str = typer.Option("ja-JP", "--locale", "-l", help="言語設定"),
2424
display_name: str = typer.Option(None, "--name", "-n", help="転写ジョブの表示名"),
25-
model: str = typer.Option(None, "--model", "-m", help="使用するモデル"),
2625
):
2726
"""新しい転写ジョブを作成する"""
2827
console.print("[bold green]転写ジョブを作成します[/bold green]")
@@ -34,7 +33,6 @@ def create_transcription(
3433
content_urls=content_urls,
3534
locale=locale,
3635
display_name=display_name or "CLI Batch Transcription",
37-
model=model,
3836
)
3937

4038
response = speech_repo.create_transcription_job(request)
@@ -95,6 +93,8 @@ def get_transcription_files(
9593
table.add_column("名前", style="cyan")
9694
table.add_column("種類", style="green")
9795
table.add_column("リンク", style="yellow")
96+
for file in files:
97+
print(file)
9898

9999
for file in files:
100100
table.add_row(

template_fastapi/models/speech.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ class BatchTranscriptionRequest(BaseModel):
5858

5959
model_config = ConfigDict(extra="ignore")
6060

61-
content_urls: list[str]
61+
content_urls: list[str] = [
62+
"https://<storage_account_name>.blob.core.windows.net/<container_name>/<file1.m4a>?<sas_token>",
63+
"https://<storage_account_name>.blob.core.windows.net/<container_name>/<file2.m4a>?<sas_token>",
64+
]
6265
locale: str = "ja-JP"
63-
display_name: str | None = None
64-
model: str | None = None
65-
properties: dict[str, Any] | None = None
66+
display_name: str | None = "My Batch Transcription"
6667

6768

6869
class BatchTranscriptionResponse(BaseModel):

template_fastapi/repositories/speeches.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ class SpeechRepository:
2323
"""音声認識データを管理するリポジトリクラス"""
2424

2525
def __init__(self):
26-
self.speech_key = azure_speech_settings.azure_speech_key
27-
self.speech_region = azure_speech_settings.azure_speech_region
28-
self.speech_endpoint = azure_speech_settings.azure_speech_endpoint
26+
self.speech_key = azure_speech_settings.azure_ai_speech_api_key
27+
self.speech_endpoint = azure_speech_settings.azure_ai_speech_endpoint
2928
self.api_version = "v3.2-preview.2"
30-
self.base_url = f"{self.speech_endpoint}speechtotext/{self.api_version}"
29+
self.base_url = urljoin(self.speech_endpoint, f"speechtotext/{self.api_version}/")
3130

3231
# セッションの設定
3332
self.session = requests.Session()
@@ -55,14 +54,10 @@ def create_transcription_job(self, request: BatchTranscriptionRequest) -> BatchT
5554
"contentUrls": request.content_urls,
5655
"locale": request.locale,
5756
"displayName": request.display_name or "Batch Transcription",
58-
"model": request.model,
59-
"properties": request.properties or {},
57+
"model": None, # Whisperモデルを使用する場合はNone
58+
"properties": {},
6059
}
6160

62-
# Whisperモデルのデフォルト設定
63-
if not request.model:
64-
payload["model"] = None # Whisperモデルを使用する場合
65-
6661
try:
6762
response = self.session.post(url, headers=self.headers, data=json.dumps(payload), timeout=30)
6863
response.raise_for_status()
@@ -150,7 +145,6 @@ def delete_transcription_job(self, job_id: str) -> bool:
150145
def list_transcription_jobs(self) -> list[TranscriptionJob]:
151146
"""転写ジョブの一覧を取得する"""
152147
url = urljoin(self.base_url, "transcriptions")
153-
154148
try:
155149
response = self.session.get(url, headers=self.headers, timeout=30)
156150
response.raise_for_status()

template_fastapi/settings/azure_speech.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55

66
class Settings(BaseSettings):
7-
azure_speech_key: str = "<YOUR_SPEECH_KEY>"
8-
azure_speech_region: str = "<YOUR_SPEECH_REGION>"
9-
azure_speech_endpoint: str = "https://<YOUR_SPEECH_REGION>.api.cognitive.microsoft.com/"
7+
azure_ai_speech_api_key: str = "<YOUR_AZURE_AI_SPEECH_API_KEY>"
8+
azure_ai_speech_endpoint: str = "https://<speech-api-name>.cognitiveservices.azure.com/"
109

1110
model_config = SettingsConfigDict(
1211
env_file=".env",

0 commit comments

Comments
 (0)