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
43 changes: 40 additions & 3 deletions apps/example-apple/src/screens/SpeechScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { apple } from '@react-native-ai/apple'
import { apple, AppleSpeech, VoiceInfo } from '@react-native-ai/apple'
import { Picker } from '@react-native-picker/picker'
import { experimental_generateSpeech } from 'ai'
import React, { useState } from 'react'
import React, { useEffect, useState } from 'react'
import {
ActivityIndicator,
Alert,
Expand Down Expand Up @@ -176,6 +177,21 @@ export default function SpeechScreen() {
arrayBuffer: ArrayBufferLike
time: number
} | null>(null)
const [voices, setVoices] = useState<VoiceInfo[]>([])
const [selectedVoice, setSelectedVoice] = useState<string | null>(null)

useEffect(() => {
const loadVoices = async () => {
try {
const voiceList = await AppleSpeech.getVoices()
setVoices(voiceList)
} catch (error) {
console.error('Failed to load voices:', error)
}
}

loadVoices()
}, [])

const generateSpeech = async () => {
if (!inputText.trim() || isGenerating) return
Expand All @@ -189,6 +205,7 @@ export default function SpeechScreen() {
const result = await experimental_generateSpeech({
model: apple.speechModel(),
text: inputText,
voice: selectedVoice ?? undefined,
})

const endTime = Date.now()
Expand Down Expand Up @@ -251,7 +268,27 @@ export default function SpeechScreen() {
</TouchableOpacity>
</View>

{/* Output Section */}
{voices.length > 0 && (
<View className="border border-gray-300 p-4 mb-4">
<Text className="mb-3">Voice Selection</Text>
<View className="border border-gray-300">
<Picker
selectedValue={selectedVoice}
onValueChange={setSelectedVoice}
>
<Picker.Item label="System Default Voice" value={null} />
{voices.map((voice) => (
<Picker.Item
key={voice.identifier}
label={`${voice.name} (${voice.language})`}
value={voice.identifier}
/>
))}
</Picker>
</View>
</View>
)}

{generatedSpeech && (
<View style={styles.card}>
<View style={styles.statusRow}>
Expand Down
2 changes: 1 addition & 1 deletion packages/apple-llm/ios/speech/AppleSpeechImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ extension AVSpeechSynthesisVoice {
"identifier": self.identifier,
"name": self.name,
"language": self.language,
"quality": quality,
"quality": self.quality,
"isPersonalVoice": false,
"isNoveltyVoice": false
] as [String : Any]
Expand Down
2 changes: 1 addition & 1 deletion packages/apple-llm/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { apple, createAppleProvider } from './ai-sdk'
export { default as AppleEmbeddings } from './NativeAppleEmbeddings'
export { default as AppleFoundationModels } from './NativeAppleLLM'
export { default as AppleSpeech } from './NativeAppleSpeech'
export { default as AppleSpeech, VoiceInfo } from './NativeAppleSpeech'
export { default as AppleTranscription } from './NativeAppleTranscription'
export { default as AppleUtils } from './NativeAppleUtils'
export { addWAVHeader, AudioFormatType } from './utils'
Loading