> ## Documentation Index
> Fetch the complete documentation index at: https://docs.camb.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Translated Story Result

> Retrieves detailed results about a specific translated story using the provided `run_id` and `target_language` parameters.

Access the complete results of your story translation process with our comprehensive retrieval endpoint. This powerful interface delivers everything you need to utilize your newly translated content, including professionally synthesized audio, formatted dialogue text, and optional transcription data. The system provides these assets in a well-structured format that makes integration into your applications or content management systems straightforward and efficient.

## Accessing Your First Translated Story Results

Let's examine how to retrieve your completed translation using Python:

```python [expandable] theme={null}
import requests
import json

# Your API authentication
headers = {
    "x-api-key": "your-api-key",  # Replace with your actual API key
    "Content-Type": "application/json"
}

def get_translation_result(run_id, target_language, include_transcript=False):
    """
    Retrieves the complete results of a translated story including audio and text assets.

    Parameters:
    - run_id: The ID of the original story that was translated
    - target_language: The language code of the target language used for translation
    - include_transcript: Boolean indicating whether to include the detailed transcript (default: False)

    Returns:
    - A dictionary containing all available translation assets
    """
    try:
        # Build the request URL with optional query parameter
        base_url = f"https://client.camb.ai/apis/translated-story-result/{run_id}/{target_language}"
        if include_transcript:
            url = f"{base_url}?include_transcript=true"
        else:
            url = base_url

        # Request the translation results
        response = requests.get(
            url,
            headers=headers
        )

        # Verify the request was successful
        response.raise_for_status()

        # Parse the result information
        result_data = response.json()

        # Display information about the retrieved assets
        print("Translation assets successfully retrieved!")
        print(f"Complete Story Audio: {result_data.get('audio_url')}")
        print(f"Dialogue Audio: {result_data.get('dialogue_url')}")

        # Check if transcript was requested and is available
        if include_transcript and 'transcript' in result_data:
            print(f"Transcript entries: {len(result_data.get('transcript'))} dialogue items")

        return result_data

    except requests.exceptions.RequestException as e:
        print(f"Error retrieving translation results: {e}")
        if hasattr(e, 'response') and e.response is not None:
            print(f"Response content: {e.response.text}")
        return None

# Example usage
run_id = 12345  # Replace with your actual `run_id`
target_language = 76  # Example: French language code
translation_result = get_translation_result(run_id, target_language, include_transcript=True)
```

## Integrating Translation Results into Your Workflow

Once you've retrieved your translation results, you can integrate them into your content pipeline in numerous ways:

```python [expandable] theme={null}
def process_translation_assets(result_data, run_id):
    """
    Demonstrates common ways to process and utilize the translation assets.

    Parameters:
    - result_data: The dictionary returned from get_translation_result()
    - run_id: The ID of the translation run for file naming
    """
    if not result_data:
        print("No translation data available to process.")
        return

    # Download the complete story audio file
    if 'audio_url' in result_data:
        audio_response = requests.get(result_data['audio_url'])
        if audio_response.status_code == 200:
            # Save the audio file locally
            with open(f"translated_story_{run_id}.flac", 'wb') as f:
                f.write(audio_response.content)
            print("Complete story audio file downloaded successfully.")

    # Download the dialogue audio file
    if 'dialogue_url' in result_data:
        dialogue_response = requests.get(result_data['dialogue_url'])
        if dialogue_response.status_code == 200:
            # Save the dialogue audio file locally
            with open(f"dialogue_audio_{run_id}.flac", 'wb') as f:
                f.write(dialogue_response.content)
            print("Dialogue audio file downloaded successfully.")

    # Process the transcript if available
    if 'transcript' in result_data and result_data['transcript']:
        # Example: Export the transcript as a formatted text file
        with open(f"transcript_{run_id}.txt", 'w', encoding='utf-8') as f:
            for dialogue_item in result_data['transcript']:
                speaker = dialogue_item.get('speaker', 'Narrator')
                text = dialogue_item.get('text', '')
                f.write(f"{speaker}: {text}\n\n")
        print("Transcript exported successfully.")

        # Example: Count dialogue entries by speaker
        speaker_counts = {}
        for dialogue_item in result_data['transcript']:
            speaker = dialogue_item.get('speaker', 'Narrator')
            speaker_counts[speaker] = speaker_counts.get(speaker, 0) + 1

        print("Dialogue distribution by speaker:")
        for speaker, count in speaker_counts.items():
            print(f"  - {speaker}: {count} lines")

# Process the retrieved translation assets
run_id = 12345  # Use the same run_id from earlier
if translation_result:
    process_translation_assets(translation_result, run_id)
```

## Best Practices for Optimal Results

To maximize the effectiveness of your translated story assets, consider these professional recommendations:

1. **Content Deployment Strategy**: Plan how you'll use both the complete story audio and the separated dialogue audio in your applications. The separate dialogue track enables more sophisticated audio mixing and dynamic content presentation.

2. **Transcript Processing**: When working with the transcript data, consider extracting specific dialogue segments for interactive applications or for creating synchronized subtitles for media players.

3. **Asset Archiving**: Implement a structured archiving system for your translated assets that preserves the relationships between audio files and transcript data across multiple languages.

4. **Quality Assessment**: Review a sample of the translated content against the original to ensure the translation maintains the intended tone and meaning of your story.

5. **Error Handling**: Implement robust error handling in your integration code to gracefully manage situations where certain assets might be temporarily unavailable.


## OpenAPI

````yaml get /translated-story-result/{run_id}/{target_language}
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers:
  - url: https://client.camb.ai/apis
security: []
paths:
  /translated-story-result/{run_id}/{target_language}:
    get:
      tags:
        - Apis
        - Stories
      summary: Get Translated Story Run Info
      operationId: get_translated_run_result__run_id__target_language__get
      parameters:
        - name: run_id
          in: path
          required: true
          schema:
            $ref: '#/components/schemas/RunIDParam'
        - name: include_transcript
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/IncludeTranscriptionQuery'
        - name: target_language
          in: path
          required: true
          schema:
            $ref: '#/components/schemas/Languages'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StoryRunInfoResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
components:
  schemas:
    RunIDParam:
      type: integer
      title: Run ID
      description: >-
        The unique identifier for the run, which was generated during the
        creation process and returned upon task completion.
    IncludeTranscriptionQuery:
      type: boolean
      default: false
      description: >-
        The optional `include_transcript` query parameter determines whether the
        detailed transcript data should be included in the response.
      title: Include Transcript
    Languages:
      type: integer
      enum:
        - 1
        - 2
        - 3
        - 4
        - 5
        - 6
        - 7
        - 8
        - 9
        - 10
        - 11
        - 12
        - 13
        - 14
        - 15
        - 16
        - 17
        - 18
        - 19
        - 20
        - 21
        - 22
        - 23
        - 24
        - 25
        - 26
        - 27
        - 28
        - 29
        - 30
        - 31
        - 32
        - 33
        - 34
        - 35
        - 36
        - 37
        - 38
        - 39
        - 40
        - 41
        - 42
        - 43
        - 44
        - 45
        - 46
        - 47
        - 48
        - 49
        - 50
        - 51
        - 52
        - 53
        - 54
        - 55
        - 56
        - 57
        - 58
        - 59
        - 60
        - 61
        - 62
        - 63
        - 64
        - 65
        - 66
        - 67
        - 68
        - 69
        - 70
        - 71
        - 72
        - 73
        - 74
        - 75
        - 76
        - 77
        - 78
        - 79
        - 80
        - 81
        - 82
        - 83
        - 84
        - 85
        - 86
        - 87
        - 88
        - 89
        - 90
        - 91
        - 92
        - 93
        - 94
        - 95
        - 96
        - 97
        - 98
        - 99
        - 100
        - 101
        - 102
        - 103
        - 104
        - 105
        - 106
        - 107
        - 108
        - 109
        - 110
        - 111
        - 112
        - 113
        - 114
        - 115
        - 116
        - 117
        - 118
        - 119
        - 120
        - 121
        - 122
        - 123
        - 124
        - 125
        - 126
        - 127
        - 128
        - 129
        - 130
        - 131
        - 132
        - 133
        - 134
        - 135
        - 136
        - 139
        - 140
        - 141
        - 142
        - 143
        - 144
        - 145
        - 146
        - 147
        - 148
        - 149
        - 150
      title: Languages
      default: 1
    StoryRunInfoResponse:
      properties:
        audio_url:
          type: string
          title: Story Output Audio URL
          description: The URL pointing to the generated audio file for the story.
        dialogue_url:
          type: string
          title: Story Dialogue Audio URL
          description: >-
            The URL pointing to the audio file that contains the story's
            dialogue.
        transcript:
          type: array
          items:
            $ref: '#/components/schemas/DialogueItem'
          title: Story Transcript
          description: >-
            A collection of dialogue items representing the textual transcript
            of the story.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    DialogueItem:
      type: object
      description: >-
        A JSON that represents a single piece of dialogue or speech within a
        given time range. It includes details about the timing (start and end),
        the content of the dialogue (text), and the speaker who delivers the
        dialogue
      properties:
        start:
          type: number
          format: float
          title: Start Time
          description: The start time (in seconds) of the dialogue.
        end:
          type: number
          format: float
          title: End Time
          description: The end time (in seconds) of the dialogue.
        text:
          type: string
          title: Dialogue Text
          description: The actual text content of the dialogue spoken by the speaker.
        speaker:
          type: string
          title: Speaker Name
          description: The name or identifier of the speaker delivering the dialogue.
      required:
        - start
        - end
        - text
        - speaker
      title: DialogueItem
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        The `x-api-key` is a custom header required for authenticating requests
        to our API. Include this header in your request with the appropriate API
        key value to securely access our endpoints. You can find your API key(s)
        in the 'API' section of our studio website.

````