MCPcopy Create free account
hub / github.com/HumeAI/hume-api-examples / example2

Function example2

tts/tts-python-quickstart/app.py:60–129  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

58# call to create a voice. Then, future calls to tts endpoints can specify the
59# voice by name or generation_id.
60async def example2():
61 result1 = await hume.tts.synthesize_json(
62 utterances=[
63 PostedUtterance(
64 description="Crisp, upper-class British accent with impeccably articulated consonants and perfectly placed vowels. Authoritative and theatrical, as if giving a lecture.",
65 text="The science of speech. That's my profession; also my hobby. Happy is the man who can make a living by his hobby!",
66 )
67 ],
68 num_generations=2,
69 )
70
71 print("Example 2: Synthesizing voice options for voice creation...")
72 sample_number = 1
73
74 for generation in result1.generations:
75 print(f"Playing option {sample_number}...")
76 audio_data = base64.b64decode(generation.audio)
77
78 await play_audio(audio_data)
79 sample_number += 1
80
81 # Prompt user to select which voice they prefer
82 print("\nWhich voice did you prefer?")
83 print("1. First voice (generation ID:", result1.generations[0].generation_id, ")")
84 print("2. Second voice (generation ID:", result1.generations[1].generation_id, ")")
85
86 # For automated testing, select option 1
87 try:
88 user_choice = input("Enter your choice (1 or 2): ").strip()
89 except EOFError:
90 # If no input available (like in automated testing), default to option 1
91 user_choice = "1"
92 print("No input available, selecting option 1")
93
94 selected_index = int(user_choice) - 1
95
96 if selected_index not in [0, 1]:
97 raise ValueError("Invalid choice. Please select 1 or 2.")
98
99 selected_generation_id = result1.generations[selected_index].generation_id
100 print(f"Selected voice option {selected_index + 1} (generation ID: {selected_generation_id})")
101
102 # Save the selected voice
103 voice_name = f"higgins-{int(time.time() * 1000)}"
104 await hume.tts.voices.create(
105 name=voice_name,
106 generation_id=selected_generation_id,
107 )
108
109 print(f"Created voice: {voice_name}")
110 print("\nContinuing speech with the selected voice...")
111
112 stream = hume.tts.synthesize_json_streaming(
113 utterances=[
114 PostedUtterance(
115 voice=PostedUtteranceVoiceWithName(name=voice_name),
116 text="YOU can spot an Irishman or a Yorkshireman by his brogue. I can place any man within six miles. I can place him within two miles in London. Sometimes within two streets.",
117 description="Bragging about his abilities",

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected