AudioModelInference¶
- class ibm_watsonx_ai.foundation_models.inference.AudioModelInference(model, credentials=None, project_id=None, space_id=None, verify=None, api_client=None)[source]¶
Bases:
WMLResource
Instantiate the audio model interface
- Parameters:
model (str, optional) – type of model to use
credentials (Credentials or dict, optional) – credentials for the Watson Machine Learning instance
project_id (str, optional) – ID of the Watson Studio project
space_id (str, optional) – ID of the Watson Studio space
verify (bool or str, optional) –
You can pass one of the following as verify:
the path to a CA_BUNDLE file
the path of directory with certificates of trusted CAs
True - default path to truststore will be taken
False - no verification will be made
api_client (APIClient, optional) – initialized APIClient object with a set project ID or space ID. If passed,
credentials
andproject_id
/space_id
are not required.
Example:
from ibm_watsonx_ai import Credentials from ibm_watsonx_ai.foundation_models import AudioModelInference audio_model = AudioModelInference( model="<AUDIO MODEL>", credentials=Credentials( api_key = IAM_API_KEY, url = "https://us-south.ml.cloud.ibm.com" ), project_id=project_id )
- transcribe(file_path, language=None)[source]¶
Transcribe audio into text.
- Parameters:
file_path (str, Path, required) – The path to the audio file to transcribe
language (str, optional) – Target language to which to transcribe, e.g. ‘fr’ for French. Default is English.
Example:
file_path = "sample_audio.mp3" response = audio_model.transcribe(file_path=file_path)
Enums¶
- class AudioTranscriptionsModels¶
Bases:
StrEnum
This represents a dynamically generated Enum for Audio Transcriptions Foundation Models.
Example of getting AudioTranscriptionsModels:
# GET AudioTranscriptionsModels ENUM client.foundation_models.AudioTranscriptionsModels # PRINT dict of Enums client.foundation_models.AudioTranscriptionsModels.show()
Example Output:
{'WHISPER_TINY': 'openai/whisper-tiny'}
Example of initialising ModelInference with AudioTranscriptionsModels Enum:
from ibm_watsonx_ai.foundation_models import AudioModelInference model = AudioModelInference( model_id=client.foundation_models.AudioTranscriptionsModels.WHISPER_TINY, credentials=Credentials(...), project_id=project_id, )