Skip to content

Commit

Permalink
Query for async synthesis result
Browse files Browse the repository at this point in the history
  • Loading branch information
reuben committed Jul 19, 2022
1 parent aa779df commit 3350766
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions coqui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
""" A Python API and CLI to use Coqui services programmatically """
__version__ = "0.0.5"
__version__ = "0.0.6"

import asyncio
from collections import namedtuple
Expand Down Expand Up @@ -338,6 +338,18 @@ async def synthesize(self, voice_id, text, speed, name) -> Sample:
}
"""
)
query = gql(
"""
query Sample($id: String!) {
sample(id: $id) {
id
name
text
created_at
audio_url
}
}
""")
try:
result = await session.execute(
mutation,
Expand All @@ -358,7 +370,12 @@ async def synthesize(self, voice_id, text, speed, name) -> Sample:
for err in result["errors"]
)
raise SynthesisError(all_errors)
return Sample(**result["sample"])

sample = Sample(**result["sample"])
while sample.audio_url is None:
result = await session.execute(query, variable_values={"id": sample.id})
sample = Sample(**result["sample"])
return sample

@staticmethod
async def download_file(url, f, chunk_size=5 * 2**20):
Expand Down

0 comments on commit 3350766

Please sign in to comment.