In v2.4.3 of the ArcGIS API for Python, we released support for three AI Premium services in ArcGIS Online via the arcgis.ai module. These tools have now transitioned to General Availability and can also be run in ArcGIS Enterprise v12.2, as shown below. To learn more about those tools, please refer to this guide.

With v2.4.4 of the ArcGIS API for Python, we released support for the following three new AI Premium services. Another major enhancement introduced with this version of the API and with v12.2 of ArcGIS Enterprise is the ability to run these AI Premium services in ArcGIS Enterprise.

  1. analyze_file() - Analyzes files based on user provided instructions.
  2. transcribe_audio() - Transcribe audio files into text using machine learning models.
  3. generate_speech() - Converts input text to synthesized speech using Azure AI speech.

Note: An ArcGIS Online organizational account and internet access are required to enable and use AI capabilities in ArcGIS Enterprise. The account you specify when enabling the capabilities must be of a supported ArcGIS Online organizational account type. The capabilities must be enabled in ArcGIS Online before you can enable them in ArcGIS Enterprise.

Data and prompts used in conjunction with AI capabilities will be processed in ArcGIS Online. Any data used in conjunction with an AI capability can be sent to this external service managed by Esri

To enable this capability for your organization, click Enable, provide the credentials for an ArcGIS Online organizational account, and click Accept and enable. If the capability is already enabled and you need to update the credentials, click Update credentials, provide the new credentials, and click Update ArcGIS Online credentials.

from arcgis.gis import GIS
from arcgis.ai import image_extract_text, analyze_file, transcribe_audio, generate_speech, AIUtilsResponse
gis = GIS(profile="your_ent_admin_profile")

Analyze File

This tool analyzes files based on user provided instructions for several use-cases such as summarizing the file, extracting text, classifying contents of the file, and performing workflows that assist with understanding the file. You can analyze PDF files using this tool by providing inputs as the URL of the file hosted on *.arcgis.com domains OR as Base64 encoded file content.

Let us take a look at an example to analyze this 37 page document for District of Columbia Chief Data Officer's Annual Report in 2020.

dc_report

file_url = "https://geosaurus.maps.arcgis.com/sharing/rest/content/items/a8ca5af1fa34467699bae7d1d4d688e6/data"

Prompts to the analyze_file() method may be provided as string, list or dictionary inputs. We will see examples for all 3 below.

1. Prompt as str input

prompt_str = "Summarize the contents of the file."
summary = analyze_file(file = file_url, prompt = prompt_str)
type(summary)
arcgis.ai._utils.AIUtilsResponse

As we will continue to see with the tools within the arcgis.ai module, the results generated from running these tools in the ArcGIS API for Python are of AIUtilsResponse type.

You can verify if the request was successful using the success field of the response.

summary.success

Since AIUtilsResponse is a pydantic model, you can access the specific results of the response as shown below.

summary.results[0].value
'The file is the District of Columbia Office of the Chief Technology Officer’s 2020 Chief Data Officer Annual Report. It reviews the District’s data policy, current data management status, 2020 Enterprise Dataset Inventory (EDI) results, FOIA tracking, 2019 accomplishments, and future goals aligned with OCTO’s draft technology strategic plan.\n\nKey points:\n- The report is framed by DC’s data policy and OCTO’s draft strategic plan, especially Commitment 4: managing, organizing, and leveraging data to support government mission delivery.\n- The 2020 EDI recorded 1,915 enterprise datasets from 82 agencies, up from 1,779 datasets from 75 agencies in 2019.\n- Dataset classifications in 2020 included 859 Open (Level 0), 179 Public but Not Proactively Released (Level 1), 219 For District Government Use (Level 2), 562 Confidential (Level 3), and 97 Restricted Confidential (Level 4).\n- Of 873 Level 0 datasets, 628 were available on the Open Data Portal; 245 open datasets were still not posted there.\n- Agencies increased datasets in categories such as Education, Public Services, Transportation, Public Safety, and Business and Economic Development.\n- Sixteen datasets were retired in 2020, with OCTO retiring 13 of them.\n- The report emphasizes a FOIA–open data feedback loop. FOIAXpress usage increased, with 8,701 FOIA requests tracked in the system in FY2019, representing 80% of all reported requests.\n- 2019 accomplishments highlighted include DC receiving What Works Cities Gold certification, expanded API and middleware integration, creation of citywide domain/lookup tables, an Esri Enterprise GIS Award, employee training in GIS and BI tools, updated planimetric and orthoimage data, and launch of 311Cards.\n- Sector-specific accomplishments are described for housing, education, jobs, transportation, public safety, health, and environment. Examples include support for the 2020 Census, public dashboards like EdScape and the CFSA dashboard, the DC Opportunity Zone Marketplace, dockless scooter analysis using the DC Data Lake, public safety dashboards during the World Series, mosquito surveillance mapping, and environmental data storytelling.\n- Future goals include improving data storytelling support, focusing more deeply on housing and one government cluster, developing a streamlined data-sharing agreement system, moving more open datasets to the portal, improving API guidance, expanding use of the DC Data Lake, improving FOIA tracking and public access, developing anonymization tools, creating an interactive EDI dashboard, planning for artificial intelligence use, and revitalizing the DC Data Science User Group.\n- The report concludes by inviting public feedback on datasets, open data needs, and ways OCTO can improve.'

The tool gives us a succinct and clear summary of the document.

We will now proceed to see examples involving the other input types through this item

2. Prompt as list input

prompt_list = [
    "Describe the accomplishments from 2019 with regards to the Environment.",
    "What are the categories of data available?"
]
result_list = analyze_file(file = file_url, prompt = prompt_list)
result_list
AIUtilsResponse(success=True, meta=AIUtilsResponseMetaData(usage=None, model='gpt-5.4'), results=[AnalyzeResult(success=True, value='For the Environment, the 2019 accomplishment highlighted was OCTO’s use of data storytelling tools. The report states that environment data stories were the most popular. A featured example was the Department of General Services’ story, “The Story of a Banana Peel.” It lets students trace a banana from a farm in Ecuador through the Port of Philadelphia to a DC Public School cafeteria, and then follow how the peel is composted and becomes fertile dirt used at Nationals Park and elsewhere. The report also notes that there are many such environmental stories on the Open Data Portal.', key='unique_string_0'), AnalyzeResult(success=True, value=['Government Operations', 'Transportation', 'Education', 'Health and Human Services', 'Public Services', 'Public Safety', 'Environment', 'Business and Economic Development', 'Administrative and Other Boundaries', 'Utility and Communication', 'Property and Land', 'Financial', 'Planning Land Use and Zoning', 'Aerial Photography and Scanned Maps', 'Historic', 'Demographic', 'Cultural and Society', 'Facility and Structure', 'Recreation', 'Location', 'Technology', 'Elevation', 'Communication', 'Basemap'], key='unique_string_1')])

We can access results for the individual prompts via the prompt index provided to the results field as demonstrated below.

result_list.results[0].value
'For the Environment, the 2019 accomplishment highlighted was OCTO’s use of data storytelling tools. The report states that environment data stories were the most popular. A featured example was the Department of General Services’ story, “The Story of a Banana Peel.” It lets students trace a banana from a farm in Ecuador through the Port of Philadelphia to a DC Public School cafeteria, and then follow how the peel is composted and becomes fertile dirt used at Nationals Park and elsewhere. The report also notes that there are many such environmental stories on the Open Data Portal.'
result_list.results[1].value
['Government Operations',
 'Transportation',
 'Education',
 'Health and Human Services',
 'Public Services',
 'Public Safety',
 'Environment',
 'Business and Economic Development',
 'Administrative and Other Boundaries',
 'Utility and Communication',
 'Property and Land',
 'Financial',
 'Planning Land Use and Zoning',
 'Aerial Photography and Scanned Maps',
 'Historic',
 'Demographic',
 'Cultural and Society',
 'Facility and Structure',
 'Recreation',
 'Location',
 'Technology',
 'Elevation',
 'Communication',
 'Basemap']

The response gives us concise and complete responses for our prompts.

3. Prompt as dict input

In order to provide prompts as a dictionary, it is essential to provide the values for the key (unique values) and context keys of the dictionary for each prompt that you wish to provide.

prompt_dicts = [
    {"key": "accomplishments", "context": "Describe the accomplishments from 2019 with regards to Mappign and Analysis"},
    {"key": "takeaways", "context": "What takeaways from the report are they taking into the following year?"}
]
result_dicts = analyze_file(file = file_url, prompt = prompt_dicts)
result_dicts
AIUtilsResponse(success=True, meta=AIUtilsResponseMetaData(usage=None, model='gpt-5.4'), results=[AnalyzeResult(success=True, value={'technical_capability': 'Mapping and Analysis', 'summary': 'In 2019, Esri Inc. recognized the District of Columbia Government for creating a leading model for governments and businesses through its use of GIS. The report says Esri cited the District’s GIS work in creating greater efficiency, collaboration across departments, transparent and open government, and citizen engagement. It also noted the central GIS/IT infrastructure provided by OCTO to all agencies and the 1,200 datasets in its open data portal used to share information across departments.', 'section': 'Esri Enterprise Geographic Information System (GIS) Award'}, key='accomplishments'), AnalyzeResult(success=True, value=['The report says future work will be guided by the Draft Technology Strategic Plan for DC: Unleashing the Possible, especially Commitment 4: manage, organize, and leverage data to facilitate DC government mission delivery.', 'They plan to identify high-value mission use cases tied to Mayoral priorities, including stronger support for housing and a deeper focus on one DC government cluster in the next year.', 'They intend to continue streamlining data sharing through a multilateral data-sharing agreement template and automation of the eMOU process.', 'They will keep working to move more Level 0 datasets onto the Open Data Portal and make the Enterprise Dataset Inventory more interactive and useful.', 'They plan to continue improving FOIAXpress adoption, training, and public access, while using FOIA data to identify datasets that should be opened.', 'They want to develop technology and processes to help agencies anonymize sensitive data so it can be shared and analyzed more safely.', 'They will continue expanding use of the DC Data Lake for analytics, including support for sensitive and less sensitive datasets.', 'They plan to develop a shared District understanding and direction for using artificial intelligence in support of the Mayor’s focus areas.', 'They want to revitalize the DC Data Science User Group with regular meetings and broader participation.', 'The conclusion emphasizes continuing to serve agencies and the public, and seeking feedback on needed datasets, ideas, and improvements.'], key='takeaways')])
result_dicts.results[0].value
{'technical_capability': 'Mapping and Analysis',
 'summary': 'In 2019, Esri Inc. recognized the District of Columbia Government for creating a leading model for governments and businesses through its use of GIS. The report says Esri cited the District’s GIS work in creating greater efficiency, collaboration across departments, transparent and open government, and citizen engagement. It also noted the central GIS/IT infrastructure provided by OCTO to all agencies and the 1,200 datasets in its open data portal used to share information across departments.',
 'section': 'Esri Enterprise Geographic Information System (GIS) Award'}
result_dicts.results[1].value
['The report says future work will be guided by the Draft Technology Strategic Plan for DC: Unleashing the Possible, especially Commitment 4: manage, organize, and leverage data to facilitate DC government mission delivery.',
 'They plan to identify high-value mission use cases tied to Mayoral priorities, including stronger support for housing and a deeper focus on one DC government cluster in the next year.',
 'They intend to continue streamlining data sharing through a multilateral data-sharing agreement template and automation of the eMOU process.',
 'They will keep working to move more Level 0 datasets onto the Open Data Portal and make the Enterprise Dataset Inventory more interactive and useful.',
 'They plan to continue improving FOIAXpress adoption, training, and public access, while using FOIA data to identify datasets that should be opened.',
 'They want to develop technology and processes to help agencies anonymize sensitive data so it can be shared and analyzed more safely.',
 'They will continue expanding use of the DC Data Lake for analytics, including support for sensitive and less sensitive datasets.',
 'They plan to develop a shared District understanding and direction for using artificial intelligence in support of the Mayor’s focus areas.',
 'They want to revitalize the DC Data Science User Group with regular meetings and broader participation.',
 'The conclusion emphasizes continuing to serve agencies and the public, and seeking feedback on needed datasets, ideas, and improvements.']

The tool here correctly identifies the successes in the field of 'Mapping and Analysis' and also summarizes the key takeaways aptly.

Transcribe Audio

This tool converts audio files into written text using machine learning models. You can analyze audio by providing inputs as the URL of the audio file hosted on *.arcgis.com domains OR as Base64 encoded payload. Currently supported file formats are: .wav, .mp3, .m4a, .mp4, .aac, .ogg, .opus, .webm, .flac, .amr, .amr-wb.

We will look at an example to transcribe audio from a an audio file on my local machine converted to Base64 encoded audio payload. Please replace the path to the audio file below to an audio file on your machine.

audio_file = "D:/Github Projects/geosaurus/tests/resources/storymap/rocks.mp3"

In order to listen to audio file from the notebook experience, you can embed your audio file as shown below:

from IPython.display import Audio

Audio(filename=audio_file, embed=True)

We will now write a method that converts this file to base64 string that can be provided for transcribing to our AI tool.

import base64

def audio_to_base64(file_path):
    with open(file_path, "rb") as audio_file:
        # Read the binary data from the file
        binary_data = audio_file.read()
        # Encode the binary data to Base64 bytes
        base64_bytes = base64.b64encode(binary_data)
        # Decode to a UTF-8 string for JSON serialization
        base64_string = base64_bytes.decode("utf-8")
    return base64_string
encoded_audio = audio_to_base64(audio_file)

We will now use the transcribe_audio() method with this encoded_audio input. The method also takes a from_language optional input parameter with "en" (English) as default. To identify the languages supported in your ArcGIS Online Organization and the culture of those languages, you may invoke the languages property of the GIS object.

transcribed_text = transcribe_audio(audio = f"data:audio/mp4;base64,{encoded_audio}")
transcribed_text.results[0].value
'This large exposed rock was a favorite location for Carl Sandburg to bring a chair and orange crate for an outdoor study. He enjoyed the quiet and peacefulness of this location to edit his work. Exposed rocks like this are located throughout the area and have a long history of use, going back to the first peoples who settled the area we know today as Flat Rock.'

This pattern demonstrated to convert local files to base64 string inputs can be applied to files on your local machine for the analyze_file() method shown above as well.

Generate Speech

This tool performs the inverse operation of the Transcribe Audio tool, i.e., it converts input text to synthesized speech using Azure AI speech. The response is streamed audio. The default output format is MP3. Similar to the Transcribe Audio tool, this method also takes a from_language optional input parameter with "en" (English) as default.

Let's look at an example that converts the following text to speech.

text_input = "The ArcGIS API for Python is a powerful, modern Pythonic library that supports the latest releases of ArcGIS Enterprise and \
            ArcGIS Online and provides a consistent programmatic experience for scripting and automating across the ArcGIS product suite. It is \
            used for three key workflows involving GIS organization administration, Content management and Spatial analysis and data science."
speech = generate_speech(text = text_input)

Since the result contains synthesized audio as a string binary payload, we need to decode it to access it.

# Decode the Base64 string into binary data
audio_bytes = base64.b64decode(speech.results[0].value)

# Write the binary data to an audio file (Supported file formats - `mp3`, `raw`, `ogg`, and `webm`.)
with open("generate_speech_audio.wav", "wb") as audio_file:
    audio_file.write(audio_bytes)

Let us embed the output file in the notebook and verify the text to speech conversion.

from IPython.display import Audio

Audio(filename="generate_speech_audio.wav", embed=True)

Conclusion

The arcgis.ai module is useful when your workflows involve unstructured data in the form of documents covering information including but not limited to planning, assessments, studies, reports, etc. The audio tools can prove beneficial when your workflows involve field recordings, voice notes, inspection reports, instructions, advisories, information and isntructions. Deriving necessary information from these data sources using these services supported within the ArcGIS API for Python can improve productivity.

Below are a few related resources to further your understanding and familiarity with this concept:

  1. Introduction to AI Premium services (Part 1)
  2. Enhancing 311 Service Requests with ArcGIS AI Utility Services

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.