[连续对话判断]:完成自动持续对话和播报打断,包含回复意图判断、免唤醒追问和打断回归测试
This commit is contained in:
@@ -9,6 +9,7 @@ import subprocess
|
||||
import tempfile
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
import wave
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
@@ -104,8 +105,9 @@ class MacSayTtsProvider:
|
||||
"tts",
|
||||
)
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
output = Path(tmp) / "speech.aiff"
|
||||
command = ["say", "-o", str(output)]
|
||||
aiff_output = Path(tmp) / "speech.aiff"
|
||||
wav_output = Path(tmp) / "speech.wav"
|
||||
command = ["say", "-o", str(aiff_output)]
|
||||
if self.voice:
|
||||
command.extend(["-v", self.voice])
|
||||
command.append(clean)
|
||||
@@ -119,7 +121,23 @@ class MacSayTtsProvider:
|
||||
"macos-say",
|
||||
"tts",
|
||||
) from exc
|
||||
data = output.read_bytes()
|
||||
try:
|
||||
subprocess.run(
|
||||
["afconvert", "-f", "WAVE", "-d", "LEI16@16000", "-c", "1", str(aiff_output), str(wav_output)],
|
||||
check=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
with wave.open(str(wav_output), "rb") as handle:
|
||||
sample_rate = handle.getframerate()
|
||||
channels = handle.getnchannels()
|
||||
data = handle.readframes(handle.getnframes())
|
||||
metadata = {"text": clean}
|
||||
except (FileNotFoundError, subprocess.CalledProcessError, wave.Error):
|
||||
data = aiff_output.read_bytes()
|
||||
sample_rate = 16000
|
||||
channels = 1
|
||||
metadata = {"text": clean, "format": "aiff"}
|
||||
if not data:
|
||||
raise ProviderError(
|
||||
ErrorCode.TTS_EMPTY_AUDIO,
|
||||
@@ -128,7 +146,8 @@ class MacSayTtsProvider:
|
||||
"macos-say",
|
||||
"tts",
|
||||
)
|
||||
return AudioSegment(data, 16000, 1, 0, max(120, len(clean) * 45), {"text": clean, "format": "aiff"})
|
||||
duration_ms = int(len(data) / max(1, sample_rate * channels * 2) * 1000)
|
||||
return AudioSegment(data, sample_rate, channels, 0, max(120, duration_ms, len(clean) * 45), metadata)
|
||||
|
||||
|
||||
class CloudTtsProvider:
|
||||
|
||||
Reference in New Issue
Block a user