Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def __init__(
enable_voice_activity_events: bool = False,
model: SpeechModels | str = "latest_long",
location: str = "global",
project: NotGivenOr[str] = NOT_GIVEN,
profanity_filter: bool = False,
sample_rate: int = 16000,
min_confidence_threshold: float = _default_min_confidence,
Expand Down Expand Up @@ -185,6 +186,7 @@ def __init__(
enable_voice_activity_events(bool): whether to enable voice activity events (default: False)
model(SpeechModels): the model to use for recognition default: "latest_long"
location(str): the location to use for recognition default: "global"
project(str): the Google Cloud project to use for recognition
profanity_filter(bool): whether to filter out profanities default: False
sample_rate(int): the sample rate of the audio default: 16000
min_confidence_threshold(float): minimum confidence threshold for recognition
Expand Down Expand Up @@ -247,7 +249,7 @@ def __init__(
self._credentials_info = credentials_info
self._credentials_file = credentials_file
self._credentials = credentials
self._project_id: str | None = None
self._project_id: str | None = project if is_given(project) else None

if (
not is_given(credentials)
Expand Down Expand Up @@ -333,7 +335,8 @@ async def _create_client(self, timeout: float) -> SpeechAsyncClientV2 | SpeechAs
self._credentials_file,
scopes=["https://www.googleapis.com/auth/cloud-platform"],
)
self._project_id = project_id
if self._project_id is None:
self._project_id = project_id
client = client_cls(credentials=credentials, client_options=client_options)
else:
client = client_cls(client_options=client_options)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_google_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ async def test_recognizer_uses_project_from_credentials(self) -> None:
recognizer = stt_instance._get_recognizer(client)
assert recognizer == "projects/test-project-123/locations/global/recognizers/_"

async def test_recognizer_uses_explicit_project(self) -> None:
creds = AnonymousCredentials()
stt_instance = STT(credentials=creds, project="explicit-project")
client = await stt_instance._create_client(timeout=1.0)

assert stt_instance._get_recognizer(client) == (
"projects/explicit-project/locations/global/recognizers/_"
)

async def test_clear_error_when_project_unresolvable(self, monkeypatch) -> None:
# no project on the credentials and no ADC available: the error must
# say what is wrong instead of a confusing "default credentials not
Expand Down