Initial bot

#Working
- Sound -> Discord
- Messages -> Bot

#In-Progress
- 420 Timer
This commit is contained in:
Logan Cusano
2021-11-30 00:25:11 -05:00
parent 0dc341fd7d
commit 94b9d7422c
17 changed files with 909 additions and 0 deletions

3
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

10
.idea/Discord-Radio-Bot.iml generated Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.9 (Discord-Radio-Bot)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (Discord-Radio-Bot)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Discord-Radio-Bot.iml" filepath="$PROJECT_DIR$/.idea/Discord-Radio-Bot.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

62
bot.py Normal file
View File

@@ -0,0 +1,62 @@
import discord
import sound
import asyncio
import datetime
from discord.ext import commands
DEVICE_NAME = "VoiceMeeter Output"
BOT_TOKEN = 'OTE1MDY0OTk2OTk0NjMzNzI5.YaWKsA.Y9yaCGg_VXRL_qQVbs05vo7gSAc'
bot = commands.Bot(command_prefix='>')
async def bg_timer():
await bot.wait_until_ready()
channel = bot.get_channel(id=757379843792044102)
while not bot.is_closed():
guild = channel.guild
role_id = discord.utils.get(guild.roles, name='Superadmins').id
willie_time = ("04:20:00", "00:16:00")
print(guild.roles)
time_now = datetime.datetime.now()
time_now_str = f"{time_now.strftime('%H:%M')}:00"
print(role_id)
if 1: #time_now_str in willie_time:
await channel.send(f"<@{role_id}> hello")
print("yes")
await asyncio.sleep(30)
@bot.command()
async def ping(ctx):
await ctx.send('pong')
@bot.command()
async def join(ctx):
await bot.wait_until_ready()
discord.opus.load_opus('./opus/libopus.dll')
if discord.opus.is_loaded():
stream = sound.PCMStream()
channel = ctx.author.voice.channel
for device, index in sound.query_devices().items():
print(index, device)
if DEVICE_NAME in device:
stream.change_device(index)
break
voice_connection = await channel.connect()
voice_connection.play(discord.PCMAudio(stream))
else:
await ctx.send("Opus won't load")
@bot.command()
async def leave(ctx):
await ctx.voice_client.disconnect()
#Enable below for 420 timer
#bot.loop.create_task(bg_timer())
bot.run(BOT_TOKEN)

View File

@@ -0,0 +1 @@
<mxfile host="app.diagrams.net" modified="2021-11-24T03:14:28.811Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36" etag="pAvBMcdzF7zOr7e9IJmQ" version="15.7.3" type="device"><diagram id="ihc4jgEqaXu7Y8j248A5" name="Page-1">3ZZNj5swEIZ/DdpTKz6z6bFJk0arblspUqseXTyLXRmGmiHA/vqa2IQguun2EG3VC+DXM4z9+B2BF63z9r1mpbhHDsoLfd560TsvDIPgdmluvdJZJU5iK2Rachc0Cnv5CE70nVpLDtUkkBAVyXIqplgUkNJEY1pjMw17QDWtWrIMZsI+ZWqufpWchFWXiT/qO5CZGCoHvpvJ2RDshEowjs2ZFG28aK0RyT7l7RpUD2/gYvO2T8yeFqahoOck5DtF3zbtl+zw9uNiu/r+ptjevYrsWw5M1W7DbrHUDQSAGyBuiJoEZlgwtRnVlca64NCX8c1ojPmAWBoxMOIPIOrc6bKa0EiCcuVmbc2+0JN7c1KFtU7hwoYGjzCdAV2IC08nYKwLmAPpzuRpUIzkYboO5jyUneJGzObBkf4L6sGM+sq4IPTvUBZVv3oB5roHfQA9O48p7UZIgn3JjlAa04O/I2teQ9BeZjtn4RKiRWJTXAdHzs/N2A7B4HFx1goL/0r0kv/Ns+EzPRu/pGfDGfVPJVi3orncBEn8+naZ3O8eb2bH8QeTTs/iCpYN4pf2bDyj91mxrqf3oOHnseUNhUz0X0pZpaj5PwcxvCJEMxw/hMe5s9+JaPML</diagram></mxfile>

371
opus/LICENSE Normal file
View File

@@ -0,0 +1,371 @@
Opus-tools, with the exception of opusinfo.[ch] is available under
the following two clause BSD-style license:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Opusinfo is a fork of ogginfo from the vorbis-tools package
(https://www.xiph.org). It is available under the GPL:
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

BIN
opus/libopus.dll Normal file

Binary file not shown.

BIN
opus/opusdec.exe Normal file

Binary file not shown.

107
opus/opusdec.html Normal file
View File

@@ -0,0 +1,107 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<title>opusdec man page</title>
<meta name="generator" content="roffit">
<STYLE type="text/css">
P.level0 {
padding-left: 2em;
}
P.level1 {
padding-left: 4em;
}
P.level2 {
padding-left: 6em;
}
span.emphasis {
font-style: italic;
}
span.bold {
font-weight: bold;
}
span.manpage {
font-weight: bold;
}
h2.nroffsh {
background-color: #e0e0e0;
}
span.nroffip {
font-weight: bold;
font-size: 120%;
font-family: monospace;
}
p.roffit {
text-align: center;
font-size: 80%;
}
</STYLE>
</head><body>
<p class="level0">
<p class="level0"><a name="NAME"></a><h2 class="nroffsh">NAME</h2>
<p class="level0">opusdec - decode audio from Opus format to WAV (or simple audio output)
<p class="level0"><a name="SYNOPSIS"></a><h2 class="nroffsh">SYNOPSIS</h2>
<p class="level0"><span Class="bold">opusdec</span> [ <span Class="bold">-hV</span> ] [ <a class="bold" href="#--quiet">--quiet</a> ] [ <a class="bold" href="#--rate">--rate Hz</a> ] [ <a class="bold" href="#--gain">--gain dB</a> ] [ <a class="bold" href="#--no-dither">--no-dither</a> ] [ <a class="bold" href="#--float">--float</a> ] [ <a class="bold" href="#--force-wav">--force-wav</a> ] [ <a class="bold" href="#--packet-loss">--packet-loss pct</a> ] [ <a class="bold" href="#--save-range">--save-range file</a> ] <span Class="bold">input.opus</span> [ <span Class="bold">output.wav</span> ]
<p class="level0"><a name="DESCRIPTION"></a><h2 class="nroffsh">DESCRIPTION</h2>
<p class="level0">
<p class="level0"><span Class="bold">opusdec</span> decodes Opus files into PCM Wave (uncompressed) files.
<p class="level0">If the input file is specified as <span Class="bold">-</span> , then <span Class="bold">opusdec</span> will read from stdin. Likewise, an output filename of <span Class="bold">-</span> will cause output to be to stdout.
<p class="level0">If no output is specified <span Class="bold">opusdec</span> will attempt to play the audio in realtime if it supports audio playback on your system.
<p class="level0"><a name="OPTIONS"></a><h2 class="nroffsh">OPTIONS</h2>
<p class="level0">
<p class="level0"><a name="-h"></a><span class="nroffip">-h, --help</span>
<p class="level1">Print help message
<p class="level0"><a name="-V"></a><span class="nroffip">-V, --version</span>
<p class="level1">Display version information
<p class="level0"><a name="--quiet"></a><span class="nroffip">--quiet</span>
<p class="level1">Suppresses program output
<p class="level0"><a name="--rate"></a><span class="nroffip">--rate</span>
<p class="level1">
<p class="level1">Force decoding at sampling rate n Hz
<p class="level0"><a name="--gain"></a><span class="nroffip">--gain</span>
<p class="level1">
<p class="level1">Adjust the output volume n dB, negative values make the signal quieter.
<p class="level0"><a name="--no-dither"></a><span class="nroffip">--no-dither</span>
<p class="level1">Do not dither 16-bit output
<p class="level0"><a name="--float"></a><span class="nroffip">--float</span>
<p class="level1">32-bit floating-point files instead of 16-bit files
<p class="level0"><a name="--force-wav"></a><span class="nroffip">--force-wav</span>
<p class="level1">Force including a wav header on output (e.g. for non-wav extensions and stdout)
<p class="level0"><a name="--packet-loss"></a><span class="nroffip">--packet-loss</span>
<p class="level1">Simulate n % random Opus packet loss
<p class="level0"><a name="--save-range"></a><span class="nroffip">--save-range</span>
<p class="level1">Saves check values for every frame to a file
<p class="level1"><a name="EXAMPLES"></a><h2 class="nroffsh">EXAMPLES</h2>
<p class="level0">Decode a file <span Class="bold">input.opus</span> to <span Class="bold">output.wav</span>
<p class="level1">opusdec input.opus output.wav
<p class="level0">
<p class="level0">Play a file <span Class="bold">input.opus</span> and force output at 48000 regardless of the original sampling rate
<p class="level0"><span Class="emphasis">(48kHz output may be faster, due to avoiding resampling and some sound hardware produces higher quality output when run at 48kHz)</span>
<p class="level1">opusdec --rate 48000 input.opus
<p class="level0">
<p class="level0">Re-encode a high bitrate Opus file to a lower rate
<p class="level1">opusdec --force-wav input.opus - | opusenc --bitrate 64 - output.opus
<p class="level0">
<p class="level0">Play an http stream <span Class="bold"><a href="http://icecast.somwhere.org">http://icecast.somwhere.org</a>:8000/stream.opus</span> with the help of curl on a system with pulseaudio
<p class="level0"><span Class="emphasis">(press ctrl-c to quit)</span>
<p class="level1">curl <a href="http://icecast.somwhere.org">http://icecast.somwhere.org</a>:8000/stream.opus | padsp opusdec -
<p class="level0">
<p class="level0"><a name="AUTHORS"></a><h2 class="nroffsh">AUTHORS</h2>
<p class="level0">
<p class="level0">Jean-Marc Valin &lt;jmvalin@jmvalin.ca&gt;
<p class="level0">Gregory Maxwell &lt;greg@xiph.org&gt;
<p class="level0"><a name="BUGS"></a><h2 class="nroffsh">BUGS</h2>
<p class="level0">
<p class="level0">Opusdec does not currently reject all invalid files which it should reject. It also doesn't provide very helpful output for the corrupted files it does reject. Use <span Class="bold">opusinfo</span>(1) for somewhat better diagnostics.
<p class="level0"><a name="SEE"></a><h2 class="nroffsh">SEE ALSO</h2>
<p class="level0"><a class="manpage" href="./opusenc.html">opusenc (1)</a> <a class="manpage" href="./opusinfo.html">opusinfo (1)</a> <p class="roffit">
This HTML page was made with <a href="http://daniel.haxx.se/projects/roffit/">roffit</a>.
</body></html>

BIN
opus/opusenc.exe Normal file

Binary file not shown.

195
opus/opusenc.html Normal file
View File

@@ -0,0 +1,195 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<title>opusenc man page</title>
<meta name="generator" content="roffit">
<STYLE type="text/css">
P.level0 {
padding-left: 2em;
}
P.level1 {
padding-left: 4em;
}
P.level2 {
padding-left: 6em;
}
span.emphasis {
font-style: italic;
}
span.bold {
font-weight: bold;
}
span.manpage {
font-weight: bold;
}
h2.nroffsh {
background-color: #e0e0e0;
}
span.nroffip {
font-weight: bold;
font-size: 120%;
font-family: monospace;
}
p.roffit {
text-align: center;
font-size: 80%;
}
</STYLE>
</head><body>
<p class="level0">
<p class="level0"><a name="NAME"></a><h2 class="nroffsh">NAME</h2>
<p class="level0">opusenc - encode audio into the Opus format
<p class="level0"><a name="SYNOPSIS"></a><h2 class="nroffsh">SYNOPSIS</h2>
<p class="level0"><span Class="bold">opusenc</span> [ <a class="bold" href="#-h">-h</a> ] [ <a class="bold" href="#-V">-V</a> ] [ <a class="bold" href="#--help-picture">--help-picture</a> ] [ <a class="bold" href="#--quiet">--quiet</a> ] [ <a class="bold" href="#--bitrate">--bitrate</a> <span Class="emphasis">kbit/sec</span> ] [ <a class="bold" href="#--vbr">--vbr</a> ] [ <a class="bold" href="#--cvbr">--cvbr</a> ] [ <a class="bold" href="#--hard-cbr">--hard-cbr</a> ] [ <a class="bold" href="#--comp">--comp</a> <span Class="emphasis">complexity</span> ] [ <a class="bold" href="#--framesize">--framesize</a> <span Class="emphasis">2.5, 5, 10, 20, 40, 60</span> ] [ <a class="bold" href="#--expect-loss">--expect-loss</a> <span Class="emphasis">pct</span> ] [ <a class="bold" href="#--downmix-mono">--downmix-mono</a> ] [ <a class="bold" href="#--downmix-stereo">--downmix-stereo</a> ] [ <a class="bold" href="#--max-delay">--max-delay</a> <span Class="emphasis">ms</span> ] [ <a class="bold" href="#--title">--title</a> <span Class="emphasis">'track title'</span> ] [ <a class="bold" href="#--artist">--artist</a> <span Class="emphasis">author</span> ] [ <a class="bold" href="#--album">--album</a> <span Class="emphasis">'album title'</span> ] [ <a class="bold" href="#--genre">--genre</a> <span Class="emphasis">genre</span> ] [ <a class="bold" href="#--date">--date</a> <span Class="emphasis">YYYY-MM-DD</span> ] [ <a class="bold" href="#--comment">--comment</a> <span Class="emphasis">tag=value</span> ] [ <a class="bold" href="#--picture">--picture</a>
<p class="level0">] [ <a class="bold" href="#--padding">--padding</a> <span Class="emphasis">n</span> ] [ <a class="bold" href="#--discard-comments">--discard-comments</a> ] [ <a class="bold" href="#--discard-pictures">--discard-pictures</a> ] [ <a class="bold" href="#--raw">--raw</a> ] [ <a class="bold" href="#--raw-bits">--raw-bits</a> <span Class="emphasis">bits/sample</span> ] [ <a class="bold" href="#--raw-rate">--raw-rate</a> <span Class="emphasis">Hz</span> ] [ <a class="bold" href="#--raw-chan">--raw-chan</a> <span Class="emphasis">N</span> ] [ <a class="bold" href="#--raw-endianness">--raw-endianness</a> <span Class="emphasis">flag</span> ] [ <a class="bold" href="#--ignorelength">--ignorelength</a> ] [ <a class="bold" href="#--serial">--serial</a> <span Class="emphasis">serial number</span> ] [ <a class="bold" href="#--save-range">--save-range</a> <span Class="emphasis">file</span> ] [ <a class="bold" href="#--set-ctl-int">--set-ctl-int</a> <span Class="emphasis">ctl=value</span> ] <span Class="emphasis">input.wav</span> <span Class="emphasis">output.opus</span>
<p class="level0"><a name="DESCRIPTION"></a><h2 class="nroffsh">DESCRIPTION</h2>
<p class="level0"><span Class="bold">opusenc</span> reads audio data in Wave, AIFF, FLAC, Ogg/FLAC, or raw PCM format and encodes it into an Ogg Opus stream. If the input file is "-" audio data is read from stdin. Likewise, if the output file is "-" the Ogg Opus stream is written to stdout.
<p class="level0">Unless quieted <span Class="bold">opusenc</span> displays fancy statistics about the encoding progress.
<p class="level0"><a name="OPTIONS"></a><h2 class="nroffsh">OPTIONS</h2>
<p class="level0"><a name="General"></a><h2 class="nroffsh">General options</h2>
<p class="level0">
<p class="level0"><a name="-h"></a><span class="nroffip">-h, --help</span>
<p class="level1">Show command help
<p class="level0"><a name="-V"></a><span class="nroffip">-V, --version</span>
<p class="level1">Show the version number
<p class="level0"><a name="--help-picture"></a><span class="nroffip">--help-picture</span>
<p class="level1">Show help on attaching album art
<p class="level0"><a name="--quiet"></a><span class="nroffip">--quiet</span>
<p class="level1">Enable quiet mode. No messages are displayed.
<p class="level1"><a name="Encoding"></a><h2 class="nroffsh">Encoding options</h2>
<p class="level0">
<p class="level0"><a name="--bitrate"></a><span class="nroffip">--bitrate N.nnn</span>
<p class="level1">Set target bitrate in kbit/sec (6-256 per channel)
<p class="level1">In VBR mode this specifies the average rate for a large and diverse collection of audio. In CVBR and Hard-CBR mode it specifies the specific output bitrate.
<p class="level1">Default for &gt;=44.1kHz input is 64kbps per mono stream, 96kbps per coupled pair.
<p class="level0"><a name="--vbr"></a><span class="nroffip">--vbr</span>
<p class="level1">Use variable bitrate encoding (default) In VBR mode the bitrate may go up and down freely depending on the content to achieve more consistent quality.
<p class="level0"><a name="--cvbr"></a><span class="nroffip">--cvbr</span>
<p class="level1">Use constrained variable bitrate encoding.
<p class="level1">Outputs to a specific bitrate. This mode is analogous to CBR in AAC/MP3 encoders and managed mode in Vorbis coders. This delivers less consistent quality than VBR mode but consistent bitrate.
<p class="level0"><a name="--hard-cbr"></a><span class="nroffip">--hard-cbr</span>
<p class="level1">Use hard constant bitrate encoding.
<p class="level1">With hard-cbr every frame will be exactly the same size, similar to how speech codecs work. This delivers lower overall quality but is useful where bitrate changes might leak data in encrypted channels or on synchronous transports.
<p class="level0"><a name="--comp"></a><span class="nroffip">--comp N</span>
<p class="level1">Set encoding computational complexity (0-10, default: 10). Zero gives the fastest encodes but lower quality, while 10 gives the highest quality but slower encoding.
<p class="level0"><a name="--framesize"></a><span class="nroffip">--framesize N</span>
<p class="level1">Set maximum frame size in milliseconds (2.5, 5, 10, 20, 40, 60, default: 20)
<p class="level1">Smaller framesizes achieve lower latency but less quality at a given bitrate.
<p class="level1">Sizes greater than 20ms are only interesting at fairly low bitrates.
<p class="level0"><a name="--expect-loss"></a><span class="nroffip">--expect-loss N</span>
<p class="level1">Set expected packet loss in percent (default: 0)
<p class="level0"><a name="--downmix-mono"></a><span class="nroffip">--downmix-mono</span>
<p class="level1">Downmix to mono
<p class="level0"><a name="--downmix-stereo"></a><span class="nroffip">--downmix-stereo</span>
<p class="level1">Downmix to stereo (if &gt;2 channels input)
<p class="level0"><a name="--max-delay"></a><span class="nroffip">--max-delay N</span>
<p class="level1">Set maximum container delay in milliseconds (0-1000, default: 1000)
<p class="level1"><a name="Metadata"></a><h2 class="nroffsh">Metadata options</h2>
<p class="level0">
<p class="level0"><a name="--title"></a><span class="nroffip">--title title</span>
<p class="level1">Set the track title comment field to <span Class="emphasis">title</span>
<p class="level0"><a name="--artist"></a><span class="nroffip">--artist artist</span>
<p class="level1">Set the artist comment field to <span Class="emphasis">artist.</span> This may be used multiple times to list contributing artists individually. Note that some playback software does not display multiple artists gracefully.
<p class="level0"><a name="--album"></a><span class="nroffip">--album album</span>
<p class="level1">Set the album or collection title field to <span Class="emphasis">album</span>
<p class="level0"><a name="--date"></a><span class="nroffip">--date YYYY-MM-DD</span>
<p class="level1">Set the date comment field to <span Class="emphasis">YYYY-MM-DD.</span> This may be shortened to YYYY-MM or YYYY.
<p class="level0"><a name="--genre"></a><span class="nroffip">--genre genre</span>
<p class="level1">Set the genre comment field to <span Class="emphasis">genre.</span> This option may be specified multiple times to tag a track with multiple overlapping genres.
<p class="level0"><a name="--comment"></a><span class="nroffip">--comment tag=value</span>
<p class="level1">Add an extra comment. This may be used multiple times. The argument should be in the form "tag=value". See the vorbis-comment specification for well known tag names: <a href="http://www.xiph.org/vorbis/doc/v-comment.html">http://www.xiph.org/vorbis/doc/v-comment.html</a>
<p class="level0"><a name="--picture"></a><span class="nroffip">--picture filename|specification</span>
<p class="level1">Attach album art for the track.
<p class="level1">Either a <span Class="emphasis">filename</span> for the artwork or a more complete <span Class="emphasis">specification</span> form can be used. The picture is added to a <span Class="bold">METADATA_BLOCK_PICTURE</span> comment field similar to what is used in
<p class="level1">The <span Class="emphasis">specification</span> is a string whose parts are separated by | (pipe) characters. Some parts may be left empty to invoke default values. Passing a plain filename is just shorthand for the "||||filename" specification.
<p class="level1">The format of <span Class="emphasis">specification</span> is [<span Class="bold">type</span>]|[<span Class="bold">media-type</span>]|[<span Class="bold">description</span>]|[<span Class="bold">width</span>x<span Class="bold">height</span>x<span Class="bold">depth</span>[/<span Class="bold">colors</span>]]|<span Class="bold">filename</span>
<p class="level1"><span Class="emphasis">type</span> is an optional number describing the nature of the picture. Defined values are from one of:
<p class="level1">&nbsp; 0: Other
<p class="level1">&nbsp; 1: 32x32 pixel 'file icon' (PNG only)
<p class="level1">&nbsp; 2: Other file icon
<p class="level1">&nbsp; 3: Cover (front)
<p class="level1">&nbsp; 4: Cover (back)
<p class="level1">&nbsp; 5: Leaflet page
<p class="level1">&nbsp; 6: Media (e.g., label side of a CD)
<p class="level1">&nbsp; 7: Lead artist/lead performer/soloist
<p class="level1">&nbsp; 8: Artist/performer
<p class="level1">&nbsp; 9: Conductor
<p class="level1">&nbsp;10: Band/Orchestra
<p class="level1">&nbsp;11: Composer
<p class="level1">&nbsp;12: Lyricist/text writer
<p class="level1">&nbsp;13: Recording location
<p class="level1">&nbsp;14: During recording
<p class="level1">&nbsp;15: During performance
<p class="level1">&nbsp;16: Movie/video screen capture
<p class="level1">&nbsp;17: A bright colored fish
<p class="level1">&nbsp;18: Illustration
<p class="level1">&nbsp;19: Band/artist logotype
<p class="level1">&nbsp;20: Publisher/studio logotype
<p class="level1">The default is 3 (front cover). More than one --picture option can be specified to attach multiple pictures. There may only be one picture each of type 1 and 2 in a file.
<p class="level1"><span Class="emphasis">media-type</span> is optional. If left blank, it will be detected from the file. For best compatibility with players, use pictures with a <span Class="emphasis">media-type</span> of image/jpeg or image/png. The <span Class="emphasis">media-type</span> can also be "--&gt;" to mean that <span Class="emphasis">filename</span> is actually a URL to an image, though this use is discouraged. The file at the URL will not be fetched. The URL itself is stored in the metadata.
<p class="level1"><span Class="emphasis">description</span> is optional. The default is an empty string.
<p class="level1">The next part specifies the resolution and color information. If the <span Class="emphasis">media-type</span> is image/jpeg, image/png, or image/gif, this can usually be left empty and the information will be read from the file. Otherwise, you must specify the width in pixels, height in pixels, and color depth in bits-per-pixel. If the image has indexed colors you should also specify the number of colors used. If possible, these are checked against the file for accuracy.
<p class="level1"><span Class="emphasis">filename</span> is the path to the picture file to be imported, or the URL if the <span Class="emphasis">media-type</span> is "--&gt;".
<p class="level0"><a name="--padding"></a><span class="nroffip">--padding n</span>
<p class="level1">Reserve <span Class="emphasis">n</span> extra bytes for metadata tags. This can make later tag editing more efficient. Defaults to 512.
<p class="level0"><a name="--discard-comments"></a><span class="nroffip">--discard-comments</span>
<p class="level1">Don't propagate metadata tags from the input file.
<p class="level0"><a name="--discard-pictures"></a><span class="nroffip">--discard-pictures</span>
<p class="level1">Don't propagate pictures or art from the input file.
<p class="level1"><a name="Input"></a><h2 class="nroffsh">Input options</h2>
<p class="level0">
<p class="level0"><a name="--raw"></a><span class="nroffip">--raw</span>
<p class="level1">Interpret input as raw PCM data without headers
<p class="level0"><a name="--raw-bits"></a><span class="nroffip">--raw-bits N</span>
<p class="level1">Set bits/sample for raw input (default: 16)
<p class="level0"><a name="--raw-rate"></a><span class="nroffip">--raw-rate N</span>
<p class="level1">Set sampling rate for raw input (default: 48000)
<p class="level0"><a name="--raw-chan"></a><span class="nroffip">--raw-chan N</span>
<p class="level1">Set number of channels for raw input (default: 2)
<p class="level0"><a name="--raw-endianness"></a><span class="nroffip">--raw-endianness [0/1]</span>
<p class="level1">Set the endianness for raw input: 1 for big endian, 0 for little (default: 0)
<p class="level0"><a name="--ignorelength"></a><span class="nroffip">--ignorelength</span>
<p class="level1">Ignore the data length in Wave headers. Opusenc automatically ignores the length when its implausible (very small or very large) but some STDIN usage may still need this option to avoid truncation.
<p class="level1"><a name="Diagnostic"></a><h2 class="nroffsh">Diagnostic options</h2>
<p class="level0">
<p class="level0"><a name="--serial"></a><span class="nroffip">--serial n</span>
<p class="level1">Force use of a specific stream serial number, rather than one that is randomly generated. This is used to make the encoder deterministic for testing and is not generally recommended.
<p class="level0"><a name="--save-range"></a><span class="nroffip">--save-range file</span>
<p class="level1">Save check values for every frame to a file
<p class="level0"><a name="--set-ctl-int"></a><span class="nroffip">--set-ctl-int x=y</span>
<p class="level1">Pass the encoder control x with value y (advanced). Preface with s: to direct the ctl to multistream s
<p class="level1">This may be used multiple times
<p class="level1"><a name="EXAMPLES"></a><h2 class="nroffsh">EXAMPLES</h2>
<p class="level0">
<p class="level0">Simplest usage. Take input as input.wav and produce output as output.opus:
<p class="level1">opusenc input.wav output.opus
<p class="level0">
<p class="level0">
<p class="level0">Produce a very high quality encode with a target rate of 160kbps:
<p class="level1">opusenc --bitrate 160 input.wav output.opus
<p class="level0">
<p class="level0">
<p class="level0">Record and send a live stream to an Icecast HTTP streaming server using oggfwd:
<p class="level1">arecord -c 2 -r 48000 -twav - | opusenc --bitrate 96 - - | oggfwd icecast.somewhere.org 8000 password /stream.opus
<p class="level0">
<p class="level0">
<p class="level0"><a name="NOTES"></a><h2 class="nroffsh">NOTES</h2>
<p class="level0">
<p class="level0">While it is possible to use opusenc for low latency streaming (e.g. with --max-delay set to 0 and netcat instead of Icecast) it's not really designed for this, and the Ogg container and TCP transport aren't the best tools for that application. Shell pipelines themselves will often have high buffering. The ability to set framesizes as low as 2.5 ms in opusenc mostly exists to try out the quality of the format with low latency settings, but not really for actual low latency usage.
<p class="level0">Interactive usage should use UDP/RTP directly.
<p class="level0"><a name="AUTHORS"></a><h2 class="nroffsh">AUTHORS</h2>
<p class="level0">
<p class="level0">Gregory Maxwell &lt;greg@xiph.org&gt;
<p class="level0"><a name="SEE"></a><h2 class="nroffsh">SEE ALSO</h2>
<p class="level0"><a class="manpage" href="./opusdec.html">opusdec (1)</a> <a class="manpage" href="./opusinfo.html">opusinfo (1)</a> <span Class="manpage">oggfwd (1)</span> <p class="roffit">
This HTML page was made with <a href="http://daniel.haxx.se/projects/roffit/">roffit</a>.
</body></html>

BIN
opus/opusinfo.exe Normal file

Binary file not shown.

79
opus/opusinfo.html Normal file
View File

@@ -0,0 +1,79 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<title>opusinfo man page</title>
<meta name="generator" content="roffit">
<STYLE type="text/css">
P.level0 {
padding-left: 2em;
}
P.level1 {
padding-left: 4em;
}
P.level2 {
padding-left: 6em;
}
span.emphasis {
font-style: italic;
}
span.bold {
font-weight: bold;
}
span.manpage {
font-weight: bold;
}
h2.nroffsh {
background-color: #e0e0e0;
}
span.nroffip {
font-weight: bold;
font-size: 120%;
font-family: monospace;
}
p.roffit {
text-align: center;
font-size: 80%;
}
</STYLE>
</head><body>
<p class="level0">
<p class="level0"><a name="NAME"></a><h2 class="nroffsh">NAME</h2>
<p class="level0">opusinfo - gives information about Opus files and does extensive validity checking
<p class="level0"><a name="SYNOPSIS"></a><h2 class="nroffsh">SYNOPSIS</h2>
<p class="level0"><span Class="bold">opusinfo</span> [ <a class="bold" href="#-q">-q</a> | <a class="bold" href="#-v">-v</a> ] [ <a class="bold" href="#-h">-h</a> ] [ <a class="bold" href="#-V">-V</a> ] <span Class="emphasis">file1.opus</span> <span Class="bold">...</span> <span Class="emphasis">fileN.opus</span>
<p class="level0"><a name="DESCRIPTION"></a><h2 class="nroffsh">DESCRIPTION</h2>
<p class="level0"><span Class="bold">opusinfo</span> reads one or more Opus files and prints information about stream contents (including chained and/or multiplexed streams) to standard output. It will detect (but not correct) a wide range of common defects, with many additional checks specifically for Opus streams.
<p class="level0">For all stream types <span Class="bold">opusinfo</span> will print the filename being processed, the stream serial numbers, and various common error conditions.
<p class="level0">For <span Class="bold">Opus</span> streams, information including the version used for encoding, number of channels and other header information, the bitrate and playback length, the contents of the comment header, and general statistics about the stream are printed.
<p class="level0">Opusinfo is a fork of <span Class="bold">ogginfo</span>(1) with the non-opus parts largely removed.
<p class="level0"><a name="OPTIONS"></a><h2 class="nroffsh">OPTIONS</h2>
<p class="level0">
<p class="level0"><a name="-h"></a><span class="nroffip">-h</span>
<p class="level1">Show a help and usage message.
<p class="level0"><a name="-q"></a><span class="nroffip">-q</span>
<p class="level1">Quiet mode. This may be specified multiple times. Doing so once will remove the detailed informative messages; twice will remove warnings as well.
<p class="level0"><a name="-v"></a><span class="nroffip">-v</span>
<p class="level1">Verbose mode. At the current time, this does not do anything.
<p class="level0"><a name="-V"></a><span class="nroffip">-V</span>
<p class="level1">Show program version info and exit.
<p class="level1"><a name="NOTES"></a><h2 class="nroffsh">NOTES</h2>
<p class="level0">
<p class="level0">There are many kinds of errored, invalid, non-normative, or otherwise unwise stream constructions which opusinfo will not produce warnings on. Passing opusinfo with flying colors is not certification of the correctness of a stream. Future versions may detect more error conditions.
<p class="level0"><a name="AUTHORS"></a><h2 class="nroffsh">AUTHORS</h2>
<p class="level0">
<p class="level0">Michael Smith &lt;msmith@xiph.org&gt;
<p class="level0">Gregory Maxwell &lt;greg@xiph.org&gt;
<p class="level0"><a name="SEE"></a><h2 class="nroffsh">SEE ALSO</h2>
<p class="level0">
<p class="level0"><a class="manpage" href="./opusdec.html">opusdec (1)</a> <a class="manpage" href="./opusenc.html">opusenc (1)</a> <p class="roffit">
This HTML page was made with <a href="http://daniel.haxx.se/projects/roffit/">roffit</a>.
</body></html>

57
sound.py Normal file
View File

@@ -0,0 +1,57 @@
import sounddevice as sd
from pprint import pformat
DEFAULT = 0
sd.default.channels = 2
sd.default.dtype = "int16"
sd.default.latency = "low"
sd.default.samplerate = 48000
class PCMStream:
def __init__(self):
self.stream = None
def read(self, num_bytes):
# frame is 4 bytes
frames = int(num_bytes / 4)
data = self.stream.read(frames)[0]
# convert to pcm format
return bytes(data)
def change_device(self, num):
if self.stream is not None:
self.stream.stop()
self.stream.close()
self.stream = sd.RawInputStream(device=num)
self.stream.start()
class DeviceNotFoundError(Exception):
def __init__(self):
self.devices = sd.query_devices()
self.host_apis = sd.query_hostapis()
super().__init__("No Devices Found")
def __str__(self):
return (
f"Devices \n"
f"{self.devices} \n "
f"Host APIs \n"
f"{pformat(self.host_apis)}"
)
def query_devices():
options = {
device.get("name"): index
for index, device in enumerate(sd.query_devices())
if (device.get("max_input_channels") > 0 and device.get("hostapi") == DEFAULT)
}
if not options:
raise DeviceNotFoundError()
return options