У меня есть следующий код от AWS для использования API транскрипции потоковой передачи AWS. Я хочу извлечь код внутреннего сервера и создать из него сокет.
Ссылка на код — https://github.com/awslabs/amazon-trans ... g-sdk/blob /develop/examples/simple_file.py
Пока я это написал, но это не выдает никаких ошибок и ничего не печатает.
async def write_chunks(stream,data):
# This connects the raw audio chunks generator coming from the microphone
# and passes them along to the transcription stream.
async for chunk in data:
await stream.input_stream.send_audio_event(audio_chunk=chunk)
await stream.input_stream.end_stream()
class MyEventHandler(TranscriptResultStreamHandler):
def handle_transcript_event(self, transcript_event: TranscriptEvent):
# This handler can be implemented to handle transcriptions as needed.
# Here's an example to get started.
results = transcript_event.transcript.results
for result in results:
for alt in result.alternatives:
print(alt.transcript)
async def handle_client(data):
print("Received audio")
stream = await client.start_stream_transcription(
language_code="en-US",
media_sample_rate_hz=16000,
media_encoding="pcm"
)
handler = MyEventHandler(stream.output_stream)
# This connects the raw audio chunks generator coming from the microphone
# and passes them along to the transcription stream.
await asyncio.gather(write_chunks(stream,data), handler.handle_events())
async def main():
server = await websockets.serve(handle_client, "localhost", 8282)
await server.wait_closed()
asyncio.run(main())
Подробнее здесь: https://stackoverflow.com/questions/790 ... ample-code
Создание сервера веб-сокетов из примера кода AWS Transcribe ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение