mlboydaisuke commited on
Commit
32afe2d
·
verified ·
1 Parent(s): 4c72feb

Card: the Python usage block now runs on litert-lm-api 0.16.1 / 0.17.1 (send_message returns a dict; response_text() helper)

Browse files
Files changed (1) hide show
  1. README.md +10 -1
README.md CHANGED
@@ -61,6 +61,8 @@ Sending the clip **without** the duration sentence works (the bundle's template
61
 
62
  The audio goes in as an audio content item; any container/sample rate the runtime's decoder reads (wav, mp3, flac — it resamples to 24 kHz). The **audio encoder must run on the CPU** (`audio_backend`), the LM may run on CPU or GPU.
63
 
 
 
64
  ```python
65
  import litert_lm
66
  from litert_lm import Message, Contents, Content
@@ -70,11 +72,18 @@ engine = litert_lm.Engine("VibeVoice-ASR-BitNet.litertlm", backend=CPU(), audio_
70
  dur = 5.86 # clip length in seconds
71
  conv = engine.create_conversation(sampler_config=litert_lm.SamplerConfig(top_k=1, top_p=1.0, temperature=0.0),
72
  max_output_tokens=256)
 
 
 
 
 
 
 
73
  resp = conv.send_message(Message.user(Contents.of([
74
  Content.AudioFile("/abs/path/clip.wav"),
75
  Content.Text(f"This is a {dur:.2f} seconds audio, please transcribe it."),
76
  ])))
77
- print("".join(c.text for c in resp.contents.contents))
78
  conv.close()
79
  ```
80
 
 
61
 
62
  The audio goes in as an audio content item; any container/sample rate the runtime's decoder reads (wav, mp3, flac — it resamples to 24 kHz). The **audio encoder must run on the CPU** (`audio_backend`), the LM may run on CPU or GPU.
63
 
64
+ Python (`pip install litert-lm-api`; this block was run as written on 0.16.1 and 0.17.1):
65
+
66
  ```python
67
  import litert_lm
68
  from litert_lm import Message, Contents, Content
 
72
  dur = 5.86 # clip length in seconds
73
  conv = engine.create_conversation(sampler_config=litert_lm.SamplerConfig(top_k=1, top_p=1.0, temperature=0.0),
74
  max_output_tokens=256)
75
+
76
+ def response_text(resp):
77
+ # litert-lm-api 0.15-0.17.1 return a dict of content parts; later builds return a Message whose str() is its text
78
+ if type(resp) is dict:
79
+ return "".join(p.get("text", "") for p in resp.get("content", []) if isinstance(p, dict))
80
+ return str(resp)
81
+
82
  resp = conv.send_message(Message.user(Contents.of([
83
  Content.AudioFile("/abs/path/clip.wav"),
84
  Content.Text(f"This is a {dur:.2f} seconds audio, please transcribe it."),
85
  ])))
86
+ print(response_text(resp))
87
  conv.close()
88
  ```
89