mirror of
https://github.com/ggerganov/ggwave.git
synced 2026-02-08 18:38:05 +08:00
ggwave-to-file : Update README.md
Removed unnecessary sys import in ggwave-to-file.py
This commit is contained in:
committed by
Georgi Gerganov
parent
79697bd196
commit
9c4f610751
@@ -86,8 +86,10 @@ curl -sS 'https://ggwave-to-file.ggerganov.com/?m=Hello world!&p=4' --output hel
|
||||
|
||||
```python
|
||||
import requests
|
||||
import wave
|
||||
|
||||
def ggwave(message: str, protocolId: int = 1, sampleRate: float = 48000, volume: int = 50, payloadLength: int = -1):
|
||||
|
||||
def ggwave(message: str, file: str, protocolId: int = 1, sampleRate: float = 48000, volume: int = 50, payloadLength: int = -1):
|
||||
|
||||
url = 'https://ggwave-to-file.ggerganov.com/'
|
||||
|
||||
@@ -101,22 +103,23 @@ def ggwave(message: str, protocolId: int = 1, sampleRate: float = 48000, volume:
|
||||
|
||||
response = requests.get(url, params=params)
|
||||
|
||||
if response == '':
|
||||
if response == '' or b'Usage: ggwave-to-file' in response.content:
|
||||
raise SyntaxError('Request failed')
|
||||
|
||||
return response
|
||||
with wave.open(file, 'wb') as f:
|
||||
f.setnchannels(1)
|
||||
f.setframerate(sampleRate)
|
||||
f.setsampwidth(2)
|
||||
f.writeframes(response.context)
|
||||
|
||||
```
|
||||
|
||||
...
|
||||
|
||||
```python
|
||||
import sys
|
||||
|
||||
# query waveform from server
|
||||
result = ggwave("Hello world!")
|
||||
# query waveform from server and write to file
|
||||
ggwave("Hello world!", "hello_world.wav")
|
||||
|
||||
# dump wav file to stdout
|
||||
sys.stdout.buffer.write(result.content)
|
||||
|
||||
```
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import sys
|
||||
import requests
|
||||
import wave
|
||||
|
||||
|
||||
Reference in New Issue
Block a user