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 @@ -283,48 +283,46 @@ async def main() -> None:
# [END analyze_audio_from_url]

# [START analyze_audio_url_with_content_range]
# Restrict to a time range with a content range string.
# Analyze audio from 5 seconds onward (milliseconds: "5000-").
print("\nAnalyzing audio from 5 seconds onward with content range '5000-'...")
# Restrict to a time window with a content range string.
# Analyze only the first 5 seconds of the audio (milliseconds: "0-5000").
print("\nAnalyzing first 5 seconds of audio with content range '0-5000'...")
audio_range_poller = await client.begin_analyze(
analyzer_id="prebuilt-audioSearch",
inputs=[
AnalysisInput(
url=audio_url,
content_range="5000-",
content_range="0-5000",
)
],
)
audio_range_result = await audio_range_poller.result()

range_audio_content = cast(AudioVisualContent, audio_range_result.contents[0])
print(f"Content range audio analysis: {range_audio_content.start_time_ms} ms onward")
range_summary = (
range_audio_content.fields.get("Summary") if range_audio_content.fields else None
print(
f"Content range audio segment:"
f" {range_audio_content.start_time_ms} ms - {range_audio_content.end_time_ms} ms"
)
if range_summary and hasattr(range_summary, "value"):
print(f"Summary: {range_summary.value}")
# [END analyze_audio_url_with_content_range]

# [START analyze_audio_url_with_additional_content_ranges]
# Additional content range examples for audio (time ranges use milliseconds):

# "2000-8000" — analyze a specific time window from 2s to 8s
print("\nAnalyzing audio from 2s to 8s with content range '2000-8000'...")
audio_window_poller = await client.begin_analyze(
# "10000-" — analyze from 10 seconds onward
print("\nAnalyzing audio from 10 seconds onward with content range '10000-'...")
audio_from_poller = await client.begin_analyze(
analyzer_id="prebuilt-audioSearch",
inputs=[
AnalysisInput(
url=audio_url,
content_range="2000-8000",
content_range="10000-",
)
],
)
audio_window_result = await audio_window_poller.result()
audio_window_content = cast(AudioVisualContent, audio_window_result.contents[0])
audio_from_result = await audio_from_poller.result()
audio_from_content = cast(AudioVisualContent, audio_from_result.contents[0])
print(
f"'2000-8000':"
f" {audio_window_content.start_time_ms} ms - {audio_window_content.end_time_ms} ms"
f"'10000-':"
f" {audio_from_content.start_time_ms} ms - {audio_from_content.end_time_ms} ms"
)

# "1200-3651" — sub-second precision (1.2s to 3.651s)
Expand All @@ -344,6 +342,24 @@ async def main() -> None:
f"'1200-3651':"
f" {audio_subsec_content.start_time_ms} ms - {audio_subsec_content.end_time_ms} ms"
)

# "0-3000,30000-" — multiple disjoint time ranges (0-3s and 30s onward)
print("\nAnalyzing audio with combined time ranges (0-3s and 30s onward) with content range '0-3000,30000-'...")
audio_combine_poller = await client.begin_analyze(
analyzer_id="prebuilt-audioSearch",
inputs=[
AnalysisInput(
url=audio_url,
content_range="0-3000,30000-",
)
],
)
audio_combine_result = await audio_combine_poller.result()
audio_combine_content = cast(AudioVisualContent, audio_combine_result.contents[0])
print(
f"'0-3000,30000-':"
f" {audio_combine_content.start_time_ms} ms - {audio_combine_content.end_time_ms} ms"
)
# [END analyze_audio_url_with_additional_content_ranges]

# [START analyze_image_from_url]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,48 +276,46 @@ def main() -> None:
# [END analyze_audio_from_url]

# [START analyze_audio_url_with_content_range]
# Restrict to a time range with a content range string.
# Analyze audio from 5 seconds onward (milliseconds: "5000-").
print("\nAnalyzing audio from 5 seconds onward with content range '5000-'...")
# Restrict to a time window with a content range string.
# Analyze only the first 5 seconds of the audio (milliseconds: "0-5000").
print("\nAnalyzing first 5 seconds of audio with content range '0-5000'...")
audio_range_poller = client.begin_analyze(
analyzer_id="prebuilt-audioSearch",
inputs=[
AnalysisInput(
url=audio_url,
content_range="5000-",
content_range="0-5000",
)
],
)
audio_range_result = audio_range_poller.result()

range_audio_content = cast(AudioVisualContent, audio_range_result.contents[0])
print(f"Content range audio analysis: {range_audio_content.start_time_ms} ms onward")
range_summary = (
range_audio_content.fields.get("Summary") if range_audio_content.fields else None
print(
f"Content range audio segment:"
f" {range_audio_content.start_time_ms} ms - {range_audio_content.end_time_ms} ms"
)
if range_summary and hasattr(range_summary, "value"):
print(f"Summary: {range_summary.value}")
# [END analyze_audio_url_with_content_range]

# [START analyze_audio_url_with_additional_content_ranges]
# Additional content range examples for audio (time ranges use milliseconds):

# "2000-8000" — analyze a specific time window from 2s to 8s
print("\nAnalyzing audio from 2s to 8s with content range '2000-8000'...")
audio_window_poller = client.begin_analyze(
# "10000-" — analyze from 10 seconds onward
print("\nAnalyzing audio from 10 seconds onward with content range '10000-'...")
audio_from_poller = client.begin_analyze(
analyzer_id="prebuilt-audioSearch",
inputs=[
AnalysisInput(
url=audio_url,
content_range="2000-8000",
content_range="10000-",
)
],
)
audio_window_result = audio_window_poller.result()
audio_window_content = cast(AudioVisualContent, audio_window_result.contents[0])
audio_from_result = audio_from_poller.result()
audio_from_content = cast(AudioVisualContent, audio_from_result.contents[0])
print(
f"'2000-8000':"
f" {audio_window_content.start_time_ms} ms - {audio_window_content.end_time_ms} ms"
f"'10000-':"
f" {audio_from_content.start_time_ms} ms - {audio_from_content.end_time_ms} ms"
)

# "1200-3651" — sub-second precision (1.2s to 3.651s)
Expand All @@ -337,6 +335,24 @@ def main() -> None:
f"'1200-3651':"
f" {audio_subsec_content.start_time_ms} ms - {audio_subsec_content.end_time_ms} ms"
)

# "0-3000,30000-" — multiple disjoint time ranges (0-3s and 30s onward)
print("\nAnalyzing audio with combined time ranges (0-3s and 30s onward) with content range '0-3000,30000-'...")
audio_combine_poller = client.begin_analyze(
analyzer_id="prebuilt-audioSearch",
inputs=[
AnalysisInput(
url=audio_url,
content_range="0-3000,30000-",
)
],
)
audio_combine_result = audio_combine_poller.result()
audio_combine_content = cast(AudioVisualContent, audio_combine_result.contents[0])
print(
f"'0-3000,30000-':"
f" {audio_combine_content.start_time_ms} ms - {audio_combine_content.end_time_ms} ms"
)
# [END analyze_audio_url_with_additional_content_ranges]

# [START analyze_image_from_url]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,10 @@ def test_sample_analyze_audio_url_with_content_ranges(self, contentunderstanding
"""Test analyzing an audio URL with various content range string options.

This test validates:
1. "5000-" — from 5 seconds onward
2. "2000-8000" — specific time window
1. "0-5000" — first 5 seconds
2. "10000-" — from 10 seconds onward
3. "1200-3651" — sub-second precision
4. "0-3000,30000-" — combined time ranges

02_AnalyzeUrl.AnalyzeAudioUrlWithTimeContentRangesAsync()
"""
Expand All @@ -661,67 +662,63 @@ def test_sample_analyze_audio_url_with_content_ranges(self, contentunderstanding
assert full_result.contents is not None
full_audio = cast(AudioVisualContent, full_result.contents[0])
full_duration = (full_audio.end_time_ms or 0) - (full_audio.start_time_ms or 0)
full_phrase_count = len(full_audio.transcript_phrases) if full_audio.transcript_phrases else 0
print(f"[PASS] Full audio: {len(full_audio.markdown or '')} chars, {full_phrase_count} phrases, {full_duration} ms")
print(f"[PASS] Full audio: {len(full_audio.markdown or '')} chars, {full_duration} ms")

# "5000-" — from 5 seconds onward
print("\nAnalyzing audio from 5 seconds onward with content range '5000-'...")
from_poller = client.begin_analyze(
# "0-5000" — first 5 seconds
print("\nAnalyzing first 5 seconds with content range '0-5000'...")
range_poller = client.begin_analyze(
analyzer_id="prebuilt-audioSearch",
inputs=[
AnalysisInput(
url=url,
content_range="5000-",
content_range="0-5000",
)
],
polling_interval=10,
)
from_result = from_poller.result()
assert from_result.contents is not None
from_audio = cast(AudioVisualContent, from_result.contents[0])
assert (from_audio.start_time_ms or 0) >= 5000, (
f"'5000-' audio StartTime ({from_audio.start_time_ms} ms) should be >= 5000 ms"
range_result = range_poller.result()
assert range_result.contents is not None
range_audio = cast(AudioVisualContent, range_result.contents[0])
assert (range_audio.end_time_ms or 0) > (range_audio.start_time_ms or 0), (
"'0-5000' should have EndTime > StartTime"
)
assert len(full_audio.markdown or '') >= len(from_audio.markdown or ''), (
f"Full audio markdown ({len(full_audio.markdown or '')} chars) should be >= range-limited ({len(from_audio.markdown or '')} chars)"
assert (range_audio.start_time_ms or 0) >= 0, (
f"'0-5000' audio StartTime ({range_audio.start_time_ms} ms) should be >= 0 ms"
)
from_phrase_count = len(from_audio.transcript_phrases) if from_audio.transcript_phrases else 0
assert full_phrase_count >= from_phrase_count, (
f"Full audio ({full_phrase_count} phrases) should have >= phrases than range-limited ({from_phrase_count})"
assert (range_audio.end_time_ms or 0) <= 5000, (
f"'0-5000' audio EndTime ({range_audio.end_time_ms} ms) should be <= 5000 ms"
)
print(f"[PASS] '5000-': {len(from_audio.markdown or '')} chars, {from_phrase_count} phrases")
assert range_audio.markdown, "'0-5000' should have markdown"
assert len(range_audio.markdown) > 0, "'0-5000' markdown should not be empty"
range_duration = (range_audio.end_time_ms or 0) - (range_audio.start_time_ms or 0)
assert full_duration >= range_duration, (
f"Full audio duration ({full_duration} ms) should be >= range-limited duration ({range_duration} ms)"
)
print(f"[PASS] '0-5000': {len(range_audio.markdown)} chars, {range_duration} ms")

# "2000-8000" — specific time window from 2s to 8s
print("\nAnalyzing audio from 2s to 8s with content range '2000-8000'...")
window_poller = client.begin_analyze(
# "10000-" — from 10 seconds onward
print("\nAnalyzing audio from 10 seconds onward with content range '10000-'...")
from_poller = client.begin_analyze(
analyzer_id="prebuilt-audioSearch",
inputs=[
AnalysisInput(
url=url,
content_range="2000-8000",
content_range="10000-",
)
],
polling_interval=10,
)
window_result = window_poller.result()
assert window_result.contents is not None
window_audio = cast(AudioVisualContent, window_result.contents[0])
assert (window_audio.end_time_ms or 0) > (window_audio.start_time_ms or 0), (
"'2000-8000' should have EndTime > StartTime"
)
assert (window_audio.start_time_ms or 0) >= 2000, (
f"'2000-8000' audio StartTime ({window_audio.start_time_ms} ms) should be >= 2000 ms"
)
assert (window_audio.end_time_ms or 0) <= 8000, (
f"'2000-8000' audio EndTime ({window_audio.end_time_ms} ms) should be <= 8000 ms"
from_result = from_poller.result()
assert from_result.contents is not None
from_audio = cast(AudioVisualContent, from_result.contents[0])
assert (from_audio.end_time_ms or 0) > (from_audio.start_time_ms or 0), (
"'10000-' should have EndTime > StartTime"
)
assert window_audio.markdown, "'2000-8000' should have markdown"
assert len(window_audio.markdown) > 0, "'2000-8000' markdown should not be empty"
window_duration = (window_audio.end_time_ms or 0) - (window_audio.start_time_ms or 0)
assert full_duration >= window_duration, (
f"Full audio duration ({full_duration} ms) should be >= time-windowed duration ({window_duration} ms)"
assert (from_audio.start_time_ms or 0) >= 10000, (
f"'10000-' audio StartTime ({from_audio.start_time_ms} ms) should be >= 10000 ms"
)
print(f"[PASS] '2000-8000': {len(window_audio.markdown)} chars, {window_duration} ms")
assert from_audio.markdown, "'10000-' should have markdown"
print(f"[PASS] '10000-': {len(from_audio.markdown)} chars")

# "1200-3651" — sub-second precision
print("\nAnalyzing audio with sub-second precision (1.2s to 3.651s) with content range '1200-3651'...")
Expand Down Expand Up @@ -755,4 +752,25 @@ def test_sample_analyze_audio_url_with_content_ranges(self, contentunderstanding
)
print(f"[PASS] '1200-3651': {len(subsec_audio.markdown)} chars, {subsec_duration} ms")

# "0-3000,30000-" — combined time ranges
print("\nAnalyzing audio with combined time ranges (0-3s and 30s onward) with content range '0-3000,30000-'...")
combine_poller = client.begin_analyze(
analyzer_id="prebuilt-audioSearch",
inputs=[
AnalysisInput(
url=url,
content_range="0-3000,30000-",
)
],
polling_interval=10,
)
combine_result = combine_poller.result()
assert combine_result.contents is not None
combine_audio = cast(AudioVisualContent, combine_result.contents[0])
assert (combine_audio.end_time_ms or 0) > (combine_audio.start_time_ms or 0), (
"'0-3000,30000-' should have EndTime > StartTime"
)
assert combine_audio.markdown, "'0-3000,30000-' should have markdown"
print(f"[PASS] '0-3000,30000-': {len(combine_audio.markdown)} chars")

print("\n[SUCCESS] All audio URL content range assertions passed")