Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Swift client for Hume AI APIs

License

NotificationsYou must be signed in to change notification settings

HumeAI/hume-swift-sdk

Repository files navigation

Hume AI Swift SDK

Integrate Hume APIs directly into your Swift application

Documentation

API reference documentation is availablehere.

Installation

Adding to your Xcode project

  1. Open project settings > Package Dependencies
  2. Click the + button to add a package dependency
  3. Enter SDK URL (https://github.com/HumeAI/hume-swift-sdk.git)
  4. Set the version rule (we recommend pinning to a specific version)
  5. Click "Add Package"
  6. Add thePrivacy - Microphone Usage Description entry to yourInfo.plist
  7. (Optional) If you plan to support background audio, select the "Audio, Airplay, and Picture and Picture" option in the "Background Modes" section of your project capabilities.

Adding to yourPackage.swift

    dependencies: [        .package(url: "https://github.com/HumeAI/hume-swift-sdk.git", from: "x.x.x")    ]

Usage

Voice Chat

The SDK provides aVoiceProvider abstraction that manages active socket connection against the/chat endpoint. This abstraction handles and coordinates the audio stack.

Capabilities

  • Pipes output audio fromaudio_output events into SoundPlayer to play back in realtime.
  • VoiceProvider.connect(...) opens and connects to the/chatsocket, waits for thechat_metadata event to be received, and starts the microphone.
  • VoiceProvider.disconnect() closes the socket, stops the microphone, and stops all playback.

Example

import Humelettoken=tryawait myAccessTokenClient.fetchAccessToken()humeClient=HumeClient(options:.accessToken(token: token))letvoiceProvider=VoiceProviderFactory.getVoiceProvider(client: humeClient)voiceProvider.delegate= myDelegate// Request permission to record audio. Be sure to add `Privacy - Microphone Usage Description`// to your Info.plistifMicrophonePermission.current==.undetermined{letgranted=awaitMicrophonePermission.requestPermissions()guard grantedelse{print("user declined mic permsissions")return}}elseifMicrophonePermission.current==.denied{print("user previously declined mic permissions") // ask user to update in settingsreturn}letsessionSettings=SessionSettings(    systemPrompt:"my optional system prompt",    variables:["myCustomVariable": myValue,"datetime":Date().formattedForSessionSettings()])tryawait voiceProvider.connect(    configId: myConfigId,    configVersion:nil,    sessionSettings: sessionSettings)// Sending user text input manuallyawaitself.voiceProvider.sendUserInput(message:"Hey, how are you?")

Listening forVoiceProvider updates

ImplementVoiceProviderDelegate methods to be notified of events, errors, meter data, state, etc.

TTS

Example

import Humelettoken=tryawait myAccessTokenClient.fetchAccessToken()humeClient=HumeClient(options:.accessToken(token: token))letttsClient= humeClient.ttsletpostedUtterances:[PostedUtterance]=[PostedUtterance(    description: voiceDescription,    speed: speed,    trailingSilence: trailingSilence,    text: text,    voice:.postedUtteranceVoiceWithId(PostedUtteranceVoiceWithId(id:"<config ID>", provider:.humeAi)))]letfmt=.wav(FormatWav()let request=PostedTts(    context:nil,    numGenerations:1,    splitUtterances:nil,    stripHeaders:nil,    utterances: postedUtterances,    instantMode:true,    format: fmt)let stream= tts.synthesizeFileStreaming(request: request)fortryawaitdata in stream{    // convert data to SoundClipguardlet soundClip=SoundClip.from(data)else{print("warn: failed to create sound clip")return}                // play SoundClip with ttsPlayertryawait ttsPlayer.play(soundClip: soundClip, format: fmt)    _data.append(data)}

Beta Status

This SDK is in beta, and there may be breaking changes between versions without a majorversion update. Therefore, we recommend pinning the package version to a specific version.This way, you can install the same version each time without breaking changes.

Known Issues and Limitations

  • Audio interruptions (e.g. phone calls) are not yet handled.
  • Manually starting/stoppingAVAudioSession will likely break an active voice session. Leave all audio handling toAudioHub. If you need to add your own output audio nodes, see `AudioHub.addNode(_:)
  • Input metering is not yet implemented.

About

Swift client for Hume AI APIs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors5


[8]ページ先頭

©2009-2025 Movatter.jp